if len(TxtSearch.Text)=0 then listbox1.listindex=-1 else dim value As String = TxtSearch.Text Dim I As Integer dim FoundAt As Integer = -1 FoundAt = -1 for i = 0 to listbox1.ListCount-1 search1=Mid(listbox1.cell(i,0),1,Len(TxtSearch.Text.Trim)) if instr(search1,value) > 0 then FoundAt = i exit end next if FoundAt >= 0 then listbox1.ListIndex = FoundAt ListBox1.InvalidateCell(i,0) else listbox1.listindex=-1 end if end if

Personally I would move the code to a method, I don't like placing code in any action events, what I do is either call a function or a method from the action event, this allows you to call your function from somewhere else in your code if needed.