[RESOLVED] Search combobox using instr
Hi all
I am creating a movie player which lists movie files from various folders/subfolders in a combobox (tsFileList). I'd like to be able to enter the movie name into a textbox (txtSearch), find that text in the combobox (using instr), then automatically select the found item.
I'd like to use instr as some of the items in the combobox contains full file paths.
Any help would be greatly appreciated as I can't seem to find an answer for this in a web search.
Regards
Colin
Re: Search combobox using instr
Have you looked at AutoComplete?
Re: Search combobox using instr
Code:
Dim found As Boolean = False
If TextBox1.Text = "" Then Exit Sub
For x As Integer = 0 To ComboBox1.Items.Count - 1
If ComboBox1.Items(x).ToString.Contains(TextBox1.Text) Then
ComboBox1.SelectedIndex = x
found = True
Exit For
End If
Next
Re: Search combobox using instr
Thanks dbasnett
Code worked great. Modified it as shown below to enable search to resume from last found item.
Code:
1:
For x As Integer = n To tsFileList.Items.Count - 1
If tsFileList.Items(x).ToString.Contains(txtSearch.Text) Then
tsFileList.SelectedIndex = x
found = True
prompt = MsgBox("Search again?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "")
If prompt = vbNo Then
Exit Sub
ElseIf prompt = vbYes Then
n = x + 1
GoTo 1
End If
Exit For
End If
Next
That really helped me out.
kindest regards
Colin