[RESOLVED] How to speed-up deleting of items from ListView?
Hello
My application uses the ListView component which contains around 5000 items.
The component has got set up the property MultiSelect = true and user can select several items and after click on button these items will be selected.
This functionality doesn't work fine in case that user select all rows and clicks on button. It takes several seconds and application is frozen.
Here is my delete function:
Code:
Private Sub RemoveStations()
Dim I As Integer
For I = lstAssignedStations.ListItems.count To 1 Step -1
If lstAssignedStations.ListItems(I).Selected Then
lstAssignedStations.ListItems.Remove lstAssignedStations.ListItems(I).Key
End If
Next I
End Sub
How can I speed-up this functionality?
Thanks
Re: How to speed-up deleting of items from ListView?
You can use this sample code to determine selected items, then loop through list of selected indexes and delete each item.
Difference is - you won't have to loop through all listitems.
ps, let me know if you have troubles implementing all of the above.
Re: How to speed-up deleting of items from ListView?
Thanks
This is cool think. I will certainly optimalize my functionality.
But I think it will solve my problem when user select all or large range of rows from component.
Why lstAssignedStations.ListItems.Clear is so speedy ?
Can I disable redrawing of component during deleting? Maybe it will help.
Re: How to speed-up deleting of items from ListView?
Sure, try
Private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long) As Long
and then before the deleting
LockWindowUpdate MyListview.hwnd
and after
LockWindowUpdate False
Re: How to speed-up deleting of items from ListView?
Thanks
It works perfectly.
:check:
Re: How to speed-up deleting of items from ListView?
Your're welcome and thanks for letting me know it worked. The best way to let everyone know that you have your answer is by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item.