I have a list of words. The list contains about 100-200 text strings (it's names of metro stations actually).
I want to make an auto-complete textbox. For an example, user press 'N' letter, then an (ending of) appropriate option appear (only one option). The ending must be selected.
How to do that?
PS1: I guess, there is a textbox control with a Property something like this:
List<string> AppropriateOptions{/* ... */}
PS2: sorry for my english. If you didn't understand -> ask me and I will try to explain!
Just in case @leniel's link goes down, here's some code that does the trick:
I want to add that the standard autocomplete for TextBox does only work from the beginning of your strings, so if you hit N only strings starting with N will be found. If you want to have something better, you have to use some different control or implement the behavior for yourself (i.e. react on TextChanged Event with some timer to delay execution, than filter your tokenlist searching with IndexOf(inputString) and then set your AutoCompleteSource to the filtered list.
Use combo box, sets its datasource or give hard coded entries but set the following properties:
Use a ComboBox instead of a TextBox. The following example will autocomplete, matching any piece of the text, not just the starting letters.
This should be a complete form, just add your own data source, and data source column names. :-)
}
The answer link by Leniel was in vb.net, thanks Joel for your entry. Supplying my code to make it more explicit:
You want to set the
TextBox.AutoCompleteSource
toCustomSource
and then add all of your strings to itsAutoCompleteCustomSource
property, which is aStringCollection
. Then you should be good to go.