|
-
March 2nd, 2003, 07:49 AM
#1
Delete Checked Items in ListView
Hi All ,
I have written a Subroutine to DELETE all of the checked Items in a ListView fixed in 'Details' Mode and has Checkboxes at all items.
' Routine to Remove Checked Items in a ListView
' Example Usage : RemoveCheckedItemsLV(Listview1)
Public Sub RemoveCheckedItemsLV(ByRef LV As ListView)
LV.BeginUpdate() ' Turn off the ListView
Do Until LV.CheckedIndices.Count = 0
Dim i As Integer
For i = 0 To LV.Items.Count - 1
If LV.Items(i).Checked = True Then
LV.Items.RemoveAt(i)
Exit For ' Fresh Start the Loop again INDEX CHANGED
End If
Next
Loop
LV.EndUpdate() ' Turn on the Listview
End Sub
When I have Hundreds of Items it seems too slow. Is there another way to delete Checked Items that is quicker.
Nick
-
March 3rd, 2003, 09:37 AM
#2
Go from then end of the items back to 0, that way their indexes don't change every time one is deleted... something like
For i = ListView.Items.Count to 0 step -1
if ListView.Items(i).Selected then
ListView.Items(i).remove
end if
next i
-
March 3rd, 2003, 10:32 AM
#3
this also worked
Public Sub RemoveCheckedItems()
ListView1.BeginUpdate() ' Turn off the ListView
Dim I As Integer
For I = ListView1.Items.Count - 1 To 0 Step -1
If ListView1.Items(I).Checked = True Then
ListView1.Items.RemoveAt(I)
End If
Next I
ListView1.EndUpdate() ' Turn on the Listview
End Sub
-
March 3rd, 2003, 09:45 PM
#4
Thanks All who Replied . It is such a simple solution and that is exactly why I missed it. Yes work from the END of the list not the start. I wish I had that thought. I will try the code that way.
Thanks Again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|