C # implements ComboBox automatic matching characters

Source: Internet
Author: User
Tags foreach

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.