Let ComboBox have find function in WPF

Source: Internet
Author: User

Requirements: Due to the number of data sources of the ComboBox binding more, if the user in the drop-down column to find, it will inevitably be inconvenient, so you need to let the ComboBox can input content, and hope that according to user input content to automatically match, so efficiency will improve!

First add a ComboBox in XAML:

<Grid>
<combobox Istextsearchenabled="False" iseditable= "True"   height= " = "left" margin= "12,23,0,0" name= "comboBox1" verticalalignment= "Top" width= "120" Span class= "PLN" >  keyup= "Combobox1_keyup" />

</Grid>

First look at the properties of the setting:
Iseditable is the text edit in the text box that enables or disables the ComboBox, allowing the ComboBox to enter content
Istextsearchenabled is whether to turn on Textsearch, which is turned on by default
And then you set the data source for the ComboBox.
Public Partial Class MainWindow : Window
{
List<string>List= New List<string> { "AA", "BB", "ABC", "CSD", "sdlfks" , "OSDI" ,< Span class= "PLN" > "AWD" };
        public mainwindow ()
        Span class= "pun" >{
            initializecomponent ();
            comboBox1 itemssource = List
}

Write code in KeyUp, according to the current input content to go to the data source fuzzy find matching data displayed in the drop-down column, the code is as follows:

Private void combobox1_keyup(object sender, KeyEventArgs e)
{

List<string>MyList= New List<string>();
MyList=List.FindAll(Delegate(StringS) { ReturnScontains (combobox1. Text. Trim });
            comboBox1 itemssource = Mylist             comboBox1 isdropdownopen = true< Span class= "pun" >;
        }

Let ComboBox have find function in WPF

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.