954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Deleting checked values from ListView Control

Hi, i am using VB6 and in my project using List View Control. The checkboxes property is setted true. Now i want to implement a functionality so that to remove only those entries/items cheked by user from the list. Can anybody tell me how to implement this. ANY CODE

saquibaltaf
Newbie Poster
8 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Hi,

Loop thru all the List Items and if it is selected use this code to delete the item:

lvw.ListItems.Remove (2)

Above code removes second item in listview.

Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Thanx for your quick reply, but i am recieveing an error :
" Run-time error '35600';
Index out of bounds"

The code is :
Dim nI As Integer

For nI = 1 To lvBooks.ListItems.Count
If lvBooks.ListItems.Item(nI).Checked = True Then
lvBooks.ListItems.Remove (nI)
End If
Next nI

saquibaltaf
Newbie Poster
8 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Hi,

This is a Tricky Situation,

Since After Removing Selected Items, ListItems.Count Keeps on Decreasing, so u have to reverse ur "For Loop " condition.
Check this Code:

For nI = lvBooks.ListItems.Count To 1 Step -1
    If lvBooks.ListItems.Item(nI).Checked = True Then
         lvBooks.ListItems.Remove (nI)
    End If
    If lvBooks.ListItems.Count=0 Then Exit For
Next nI



Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Thanks alot QVeen72. I realy appriciate your quick reply. It's Done

saquibaltaf
Newbie Poster
8 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Hi, last year i asked this question and answered well. No i am in the same situation in VB.NET. What is to do same thing means removing checked items from list view in VB.NET

saquibaltaf
Newbie Poster
8 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

Hi, i am using VB6 and in my project using List View Control. The checkboxes property is setted true. Now i want to implement a functionality so that to remove only those entries/items cheked by user from the list. Can anybody tell me how to implement this. ANY CODE[/QUOTE]

vsr321
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

Try this code for VB.Net :

For Each lvItem As ListViewItem In ListView1.Items
    If lvItem.Checked Then
        lvItem.Remove()
    End If
Next


Regards
Veena

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

Thanx for your quick reply, but i am recieveing an error : " Run-time error '35600'; Index out of bounds"

The code is : Dim nI As Integer

For nI = 1 To lvBooks.ListItems.Count If lvBooks.ListItems.Item(nI).Checked = True Then lvBooks.ListItems.Remove (nI) End If Next nI

Thanxxxxx

alpesh_08b091
Newbie Poster
2 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Here is my code...

Dim lvi As ListItem
    Dim i As Integer
    Dim count As Integer
    
    count = ListView1.ListItems.count
    
    For i = 1 To count
    
        If i > count Then Exit For
        
        Set lvi = ListView1.ListItems(i)
    
        If lvi.Checked = True Then
                                              
            ListView1.ListItems.Remove (lvi.Index)
            i = i - 1
            count = count - 1
            
        End If
    Next
baune
Newbie Poster
2 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Anyone who needs help about Adding, Editing and deleting items from List view and records form Database can go through my attached help.

Hope this helps

Attachments Login_Example_with_MSAccess_DB.zip (16.19KB)
kinwang2009
Posting Whiz in Training
243 posts since Feb 2010
Reputation Points: 17
Solved Threads: 42
 

We appreciate your help. Have you ever noticed that the current thread is two years old? Please do not resurrect old threads and have a look at forum rules . Please read before posting - http://www.daniweb.com/forums/thread78223.html

Thread Closed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: