What's the easiest way to find duplicates in a ListBox and remove them?
Printable View
What's the easiest way to find duplicates in a ListBox and remove them?
I think it will be better to find the diplicated before you enter them in the ListBox.
Where does the ListBox data come from ?
My program adds items to the listbox from a file that the user can edit.
the fastest way to check before you add is the use of sendmessage
VB Code:
Option Explicit Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Const LB_FINDSTRINGEXACT = &H1A2 '------------------------------------------------------ 'then part of the sub adding the strings If SendMessageString(List1.hwnd, LB_FINDSTRINGEXACT, -1, ByVal The_string_to_add) = -1 Then List1.AddItem The_string_to_add End If
casey.
...bearing in mind that the search isn't case sensitive :p
chem
That's okay all the items are all automatically converted to upper case anyway. Thanks!