Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a TextBox search through a ListBox?

Status
Not open for further replies.

JESTAR

Programmer
Feb 13, 2002
213
GB
Hi.

I have a multiselect listbox, 10 columns. I want to be able to type in a textbox, hit a button, and the thing I typed in is highlighted in the listbox. The search should be through column 1 of the listbox.

Cheers.
 
Hi!

Use the following code in your button's click event:

Dim intRow As Integer

For intRow = 0 To Me!YourListBox.ListCount - 1
If Me!YourListBox.Column(0, intRow) = YourTextBox.Value Then
Me!YourListBox(intRow).Selected = True
Exit For
End If
Next intRow

A couple of things to note, in the column property you will use the column number that holds the data of interest, if the data is in the bound column you can use .ItemData(intRow) instead. Doing the search this way allow for an exact match only, so if no match is found(you can use a boolean variable to track that) you may want to display a message box with an appropriate comment.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top