1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
public partial class Form1 : Form
{
List<KeyValuePair<string, string>> itemlist = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("1", "abc"),
new KeyValuePair<string, string>("2", "def"),
new KeyValuePair<string, string>("3", "ghi"),
new KeyValuePair<string, string>("4", "xyz"),
new KeyValuePair<string, string>("5", "dvd"),
new KeyValuePair<string, string>("6", "fff")
};
public Form1()
{
InitializeComponent();
comboBox1.DataSource = itemlist;
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
comboBox1.DataSource = itemlist.Where(d => d.Value.Contains(comboBox1.Text)).ToList();
}
} |
Partager