我有一个组合框,用于定义屏幕上其他框的内容。
因此,如果我要在我的组合框中键入“Apple”作为员工姓名,则会导致错误,因为我的数据库中没有“Apple”员工,这意味着不会检索任何内容来填充其余的形式。
是否有我可以设置的属性或我可以编写的代码片段,以确保用户在组合框中输入的内容会突出显示绘图中的选择?
答案 0 :(得分:0)
您可以将DropDownStyle
设置为DropDownList
(而不是DropDown
)。然后用户可以输入类型,但Combobox
仅在存在这样的元素时才切换选择。
(但这确实改变了ComboBox-Appearence,所以它不再像“Freetext”那样了)
将AutoCompleteMode
设置为Suggest
,将AutoCompleteSource
设置为ListItems
,以便输入的内容不仅仅是第一个字母。 (当用户输入更多字母时,Combobox将展开并切换元素。)
答案 1 :(得分:0)
检查绑定到ComboBox的数据源(数据表,数据集等)计数
if(DataSource!=null && DataSource.rows.count>0)
{
combobox.datasource=DataSource;
combobox.refresh();
}
答案 2 :(得分:0)
我建议你做以下事情:
1.获取TextBox并将TextBox的属性设置为
AutoCompleteMode=SuggestAppend
和AutoCompleteSource = CustomSource
。
2.在数据表中添加您想要的值(可能是员工名称或您想要的任何其他列)。
3.在页面加载或任何您想要的事件中,请调出以下方法。
public bool AutoComplete()
{
try
{
DataTable dtEmpName=/////// store the employees name in this DataTable.
var empNames = dtEmpName.Select(s => s.EmpName('the column you want').Distinct().ToArray();
/////// Auto complete Name from Surname
AutoCompleteStringCollection instcol = new AutoCompleteStringCollection();
instcol.AddRange(empNames);
txtEmpNames.AutoCompleteCustomSource = instcol;
}
catch (Exception ex)
{
throw ex;
}
}