VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



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

by Fredrik Schultz (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (11 Votes)

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.

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

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

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

Download this snippet    Add to My Saved Code

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

No comments have been posted about Add only unique items to a listbox (no duplicates added). Fast and short without any loops.. Why not be the first to post a comment about Add only unique items to a listbox (no duplicates added). Fast and short without any loops..

Post your comment

Subject:
Message:
0/1000 characters