README.md

December 5, 2022 ยท View on GitHub

Fast ListView Clear Function

Description

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

More Info

ListView Control

You've got VB!

Submitted On
ByDavid Peake
LevelBeginner
User Rating4.0 (8 globes from 2 users)
CompatibilityVB 4.0 (32-bit), VB 5.0, VB 6.0
CategoryVB function enhancement
WorldVisual Basic
Archive File

Source Code

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