c# winform combobox控件,实现 输入几个字的拼音首字母可以检索数据。

2024-11-07 13:48:14
推荐回答(3个)
回答1:

参考这个:

DataTable tb = new DataTable();
            tb.Columns.Add(new DataColumn("id", typeof(int)));
            tb.Columns.Add(new DataColumn("name", typeof(string)));
            for (int i = 0; i < 10; i++)
            {
                DataRow dr = tb.NewRow();
                dr["id"] = i;
                dr["name"] = "a" + i.ToString();
                tb.Rows.Add(dr);
            }
 
            comboBox1.DataSource = tb;
            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember = "id";
            comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

回答2:

1.数据源绑定是否成功
2.autocompletemode设置为suggestAppend
3.autocompletesource设置为listitems

回答3:

用textbox和listbox自己做一个