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