VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Fast ListView Clear Function

by David Peake (1 Submission)
Category: VB function enhancement
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

The ListView's clear method becomes slow on large lists. This function removes items faster.

Inputs
ListView Control
Assumes
You've got VB!

Rate Fast ListView Clear Function

Public Sub ListView_Clear(lstListName As ListView)
Dim lCount As Long
Dim lLoop As Long
' Count items in listview
lCount = lstListName.ListItems.Count
' clear would probably be faster on a low number!
If lCount > 10 Then
  ' loop through (backwards) to remove items
  ' They're not visible so it's becomes fatser!!
  For lLoop = lCount To 1 Step -1
  
    lstListName.ListItems.Remove lLoop
  Next
  
Else
  lstListName.ListItems.Clear
End If

End Sub

Download this snippet    Add to My Saved Code

Fast ListView Clear Function Comments

No comments have been posted about Fast ListView Clear Function. Why not be the first to post a comment about Fast ListView Clear Function.

Post your comment

Subject:
Message:
0/1000 characters