I am having a hard time figuring out how to code a series of \"if\" statements that search through different dropdownlists for a specific value entered in a textbox. I was able
The solutions presented work if you want to search for an exact value in a loaded combobox.
This solution, searches for partial values also. It uses a search button and the text portion of the dropdown box as the search criteria
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
' query the dropdown object
''''''''''''
' part 9457 is a "contains" sample
' part 111 is a "startswith" sample
Dim query As IEnumerable(Of [Object]) = _
From item In cboParts.Items _
Where (item.ToString().ToUpper().StartsWith(cboParts.Text.ToUpper())) _
Select (item)
' show seached item as selected item
cboParts.SelectedItem = query.FirstOrDefault()
' "startswith" fails, so look for "contains"
If String.IsNullOrEmpty(cboParts.SelectedItem) Then
Dim query1 As IEnumerable(Of [Object]) = _
From item In cboParts.Items _
Where (item.ToString().ToUpper().Contains(cboParts.Text.ToUpper())) _
Select (item)
' show seached item as selected item
cboParts.SelectedItem = query1.FirstOrDefault()
If String.IsNullOrEmpty(cboParts.SelectedItem) Then
MsgBox("Part is not in dropdown list")
End If
End If