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

Recommended Answers

All 11 Replies

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

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

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

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

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

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.

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.