1. Use CustomSource as a hint set
Add the following code to the window load function. Suppose Unitnamelist is the list of strings that you want to add to the Drop-down list.
AutoCompleteStringCollection collection = new AutoCompleteStringCollection ();
Get list of units
list<string> unitnamelist = This.getallunitname ();
foreach (String unitname in Unitnamelist)
{
Collection. ADD (Unitname);
Console.WriteLine ("Automatic hint" + unitname);
}
This.comboBox2.AutoCompleteCustomSource = collection;
This.comboBox2.AutoCompleteSource = Autocompletesource.customsource;
This.comboBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
The AutoCompleteMode contains four cases of none,suggest,append and SuggestAppend.
None: Turn off auto-fill function
Suggest: Expand the Drop-down list and display the results of the match
Append: Auto-complement
The combination of suggestappend:suggest and append, that is, the Drop-down list is also automatically fully complement.
2. Use the items in the Drop-down list directly as a matching collection
AutoCompleteSource is set to ListItems.
//Get the list of units
list<string> unitnamelist = This.getallunitname ();
foreach (String unitname in Unitnamelist)
{
This.comboBox2.Items.Add (unitname);
}
This.comboBox2.AutoCompleteSource = Autocompletesource.listitems;