Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an auto-complete textbox in a winforms desktop application

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!

like image 486
alex4 Avatar asked Jan 07 '11 20:01

alex4


People also ask

How do you make a TextBox Autosuggested in Windows Forms?

Append displays first value of the suggestion appended or selected in the TextBox, other values can be navigated using arrow keys. SuggestAppend displays suggested values as dropdown and first value appended in the TextBox. AutoCompleteSource property sets the source for auto complete data.

How do you AutoComplete in C#?

AutoCompleteSource = AutoCompleteSource. CustomSource; AutoCompleteStringCollection col = new AutoCompleteStringCollection(); col. Add("Foo"); col. Add("Bar"); textBox1.

How do you create a text file in WinForms?

Step 1: FormDrag and down a Button from tool box and give name it as Create File. Step 2: Before creating a Text File. Right click on Solution Explorer and click on "Open Folder in Window Explorer" Go to this path.


1 Answers

Just in case @leniel's link goes down, here's some code that does the trick:

AutoCompleteStringCollection allowedTypes = new AutoCompleteStringCollection();
allowedTypes.AddRange(yourArrayOfSuggestions);
txtType.AutoCompleteCustomSource = allowedTypes;
txtType.AutoCompleteMode = AutoCompleteMode.Suggest;
txtType.AutoCompleteSource = AutoCompleteSource.CustomSource;
like image 187
Joel Avatar answered Oct 12 '22 23:10

Joel