Results 1 to 6 of 6

Thread: [RESOLVED] How to speed-up deleting of items from ListView?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    177

    Resolved [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

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    177

    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.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    177

    Re: How to speed-up deleting of items from ListView?

    Thanks

    It works perfectly.


  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width