Find & Select list item in list

I have a app with a listbox with some stock numbes in it and a textbox and a 'Find' button.
How would I enter a stock number into the textbox, click find, and have it highlight that stock number in the list so I don't have to search by eye?
Who is Participating?
Fernando SotoConnect With a Mentor RetiredCommented:
   Private Sub cbFind_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles cbFind.Click

        Dim index As Integer = -1

        index = lbStock.FindStringExact(tbFind.Text)
        If index <> -1 Then
            lbStock.SelectedIndex = index
        End If

    End Sub
Bob LearnedConnect With a Mentor Commented:
Is the ListBox bound with DisplayMember and ValueMember?

Do you want to search by value or by text?

Bob LearnedCommented:
Assuming WinForms application, not ASP.NET.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Matrix1000Author Commented:
I'd like to search by text...
Matrix1000Author Commented:
FernandoSoto your example worked great thanks!

What can I do to modify the code to show a message if the stocknumber was not found?
Matrix1000Author Commented:
figured it out thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.