Reputation: 13
Just as simple as this, I need to search an array that is binded to listbox, and user will type the text in a text box, something like Google search text box does.
This is for Windows Application using C# (3.5)
Any idea?
Upvotes: 1
Views: 6108
Reputation: 64527
WinForms TextBox controls have an AutoComplete property. This behaves the same as the Google TextBox. Here is an example:
http://csharpdotnetfreak.blogspot.com/2009/01/winforms-autocomplete-textbox-using-c.html
Upvotes: 1
Reputation: 18387
You need to use ComboBox, it has autocomplete
This is simple
Upvotes: 3
Reputation: 55049
Assuming the array is sorted in alphabetical order.
Just handle the TextChanged
event for the TextBox
and whenever it changes you use ListBox.FindString
to find the first item in the ListBox
that starts with that string and then call ListBox.TopIndex
with the index of that item to make that be the top visible item in the ListBox
.
Upvotes: 0