• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Search ListBox

Say I have a list box with over a 1000 items.  Is there an easy way to search a listbox?

So the search box is a textbox the user types in a word similar to what they are looking for...and the user clicks search...thus the listbox selects the closest word to the search word.  Is this possible or is it massive coding?

Thanks


 
0
troyhalsey
Asked:
troyhalsey
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try something like...

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index <> -1 Then
            ListBox1.SetSelected(index, True)
            ListBox1.TopIndex = index
        Else
            ListBox1.ClearSelected()
        End If
    End Sub
0
 
troyhalseyAuthor Commented:
Works great...only I changed:

Else
ExitSub
End If
End Sub

Because if I type in random numbers...it gave an error...but now it just ignores the garbage.

Thanks Idle...you have been a big help today.

Troy
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now