ComboBox input prompt (like IE Address Bar) C #

Source: Internet
Author: User

 

Recently, when working on a project, you need to use ComboBox to implement functions similar to the IE drop-down list! The most direct idea is to listen to the textchanged event of ComboBox. when the event occurs, match the matching string from the data (I saved the data using arraylist, then add it to the ComboBox drop-down list.
1: How to display the drop-down list in textchanged, because the drop-down list is usually displayed by clicking the drop-down arrow, and then use combobox1.droppeddown = true; to display the drop-down list content.
2: add content to the drop-down list: combobox1.items. Add (STR); Use this statement to add STR to the drop-down list.
3: delete the drop-down list? Because when the text of ComboBox changes, the content in the previously matched list may no longer match, so my idea is to delete all the content in the drop-down list every time the text changes, then, traverse the set again and add the matched content to the drop-down list: combobox1.items. clear (); but this statement will have a problem, that is, the cursor in the text will automatically run to the leftmost end: in this way, this idea does not continue, it is also found that sometimes the mouse will lose the cursor, and it feels bad!
4: After checking that ComboBox and textbox support the built-in search prompt function, add the following statement in form initializecomponent:
This. combobox1.autocompletecustomsource. addrange (New String [] {"10.152.154.89", "10.152.154.90", "10.152.252.10", "10.152.252.11 "});
This. combobox1.autocompletemode = system. Windows. Forms. autocompletemode. Suggest;
This. combobox1.autocompletesource = system. Windows. Forms. autocompletesource. customsource;
Here, this. combobox1.autocompletecustomsource. addrange (New String [] {"10.152.154.89", "10.152.154.90", "10.152.252.10", "10.152.252.11"}) is to add data to the search range
This. combobox1.autocompletemode = system. Windows. Forms. autocompletemode. Suggest;
Is to set the ComboBox to complete the built-in search, the default is none, there are append, and suggestappend attributes, in addition to the default none can achieve the Search Prompt function, but the appearance is different.
This. combobox1.autocompletesource = system. windows. forms. autocompletesource. customsource; specifies the search range. Here, we use new string [] {"10.152.154.89", "10.152.154.90", "10.152.252.10", "10.152.252.11"} as the search range, therefore, it is defined as customsource.
System. Windows. Forms. autocompletesource also has a allurl attribute. If you change the code
This. combobox1.autocompletemode = system. Windows. Forms. autocompletemode. Suggest; this. combobox1.autocompletesource = system. Windows. Forms. autocompletesource. allurl;
In this way, the ComboBox can implement the same functions as the IE drop-down list, and other attributes such as allsystemsources can be tried by themselves, thus completing the ComboBox Search Prompt function.

 

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.