combox 自动匹配可以设置两个属性:
cmbProdList.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cmbProdList.AutoCompleteSource = AutoCompleteSource.ListItems;
设置后可以自动匹配,但不能模糊匹配。
下面是自己实现模糊匹配方法,实际上用到DataView 过滤功能,重新绑定数据,就这么简单。
private void cmbProdList_TextChanged(object sender, EventArgs e)
{
string keys = cmbProdList.Text.Trim();
if (keys.Length > 0)
{
UserList.RowFilter = " Title LIKE '*" + keys + "*'";
cmbProdList.DroppedDown = true;
}
cmbProdList.DataSource = UserList;
cmbProdList.DisplayMember = "Title";
cmbProdList.ValueMember = "Id";
Cursor.Current = Cursors.Default;//设置鼠标显示
//cmbProdList.Refresh();
}