我在窗体表单应用程序中处理文本框自动完成时遇到问题。我的收藏显示50条搜索记录。但我只收到2个文本框建议。为什么?看看代码。我在txtInput_TextChanged事件中做这项工作。
private void txtInput_TextChanged(object sender, EventArgs e)
{
string str = txtInput.Text.ToString();
dv = new DataView(dt);
dv.RowFilter = "MedicineName like '%" + str + "%'";
for (int i = 0; i < dv.Count; i++)
{
string name = dv[i]["MedicineName"].ToString();
nameCollection.Add(name);
}
txtInput.AutoCompleteMode = AutoCompleteMode.Suggest;
txtInput.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtInput.AutoCompleteCustomSource = nameCollection;
//textboxMedicine.BorderStyle = BorderStyle.Fixed3D;
//textboxMedicine.ScrollBars = ScrollBars.Vertical;
}
我还在属性窗口中设置了autocomplete和autocompletesource。但仍然我的文本框自动填充建议无法正常工作。请帮忙
答案 0 :(得分:0)
将此AutoCompleteMode.SuggestAppend
用于AutoCompleteMode
txtInput.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
将like
更改为LIKE
dv.RowFilter = "MedicineName LIKE '%"+str+"%'";