I have found two ways to search a listbox for a string.
First way is to use api:
VB Code:
Option Explicit Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long 'Searchs a listbox for a matching string. Returns the listindex of the matching item. Function ListboxFindString(strSearchString As String, lHwndListbox As Long) As Long Const LB_FINDSTRING = &H18F ListboxFindString = SendMessage(lHwndListbox , LB_FINDSTRING, -1, ByVal strSearchString) End Function
and the second, the vb.net built-in function:
VB Code:
Dim i As Integer = ListBox1.FindString("String To Find")
Even tho the second one is much smaller, which one from those is the fastest? Anyone Know?




Reply With Quote