Tag Archives: search listbox

Find/Search for a String in a Listbox/Combobox control by using VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This will search for a String value in the Listbox or Combobox items in Visual Basic.NET, VB 2005 and Higher

            'TxtItem.Text would be a textbox control whose text string will be searched. And of course, lstItems
            'is a Listbox control or you can make it a Combobox control. The code below shows searching
            'for a  partial/exact string at either the beginning of the control or at a specified Index value.
            'Search a Listbox Control for a exact string
            lstItems.SelectedIndex = lstItems.FindStringExact(txtItem.Text)
            'Search a Listbox Control for a partial string
            lstItems.SelectedIndex = lstItems.FindString(txtItem.Text)