Search Tools Links Login

Add only unique items to a listbox (no duplicates added). Fast and short without any loops.

Use this method to avoid adding an item to a ListBox that already exists.
It's a lot faster and shorter than submissions that uses loops etc.

Original Author: Fredrik Schultz


StringToAdd = the string to add (if not already exists)
lst = your ListBox


Private Sub AddUnique(StringToAdd As String, lst As ListBox)
  lst.Text = StringToAdd
  If lst.ListIndex = -1 Then
    'it does not exist, so add it..
    lst.AddItem StringToAdd
  End If
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 88 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.