C# bindingsource.filter中存在多个条件问题
我正在尝试根据2个组合框筛选绑定源。我有一个组合框过滤器很好。第二个使用了第一个组合框,第二个基于switch语句,这让我很困惑:C# bindingsource.filter中存在多个条件问题,c#,filter,bindingsource,C#,Filter,Bindingsource,我正在尝试根据2个组合框筛选绑定源。我有一个组合框过滤器很好。第二个使用了第一个组合框,第二个基于switch语句,这让我很困惑: private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e) { string sItem; sItem = comboBox2.SelectedItem.ToString(); switch (s
private void comboBox2_SelectedIndexChanged(object sender,
System.EventArgs e)
{
string sItem;
sItem = comboBox2.SelectedItem.ToString();
switch (sItem)
{
case "Banks":
propertyInformationBindingSource.Filter = ("ClientKey ='" + comboBox1.SelectedValue + "'" And "Search = -1");
break;
case "Exam":
propertyInformationBindingSource.Filter = ("ClientKey ='" + comboBox1.SelectedValue + "'") And ("Exam = -1");
break;
case "Search Finished":
propertyInformationBindingSource.Filter = ("ClientKey ='" + comboBox1.SelectedValue + "'") And ("Finished = -1;
break;
case "All":
propertyInformationBindingSource.Filter = "ClientKey ='" + comboBox1.SelectedValue + "'";
break;
}
}
我有问题的价值后,它声称是错误的。任何帮助都会很好
谢谢我认为有一些字符串连接问题,您缺少了
Finisher=-1
的右括号
试一试
注意:如果进行的字符串连接太多,最好使用string.Format()
。它提高了可读性,比串联更有效。举个例子,第一个案例是这样的
propertyInformationBindingSource.Filter =
string.Format("ClientKey ='{0}' And Search = -1", comboBox1.SelectedValue);
@Bala R语法似乎是正确的,但我仍然没有得到预期的结果。当使用combobox2时,它总是返回时没有记录。@Korrowan如果在开关块的末尾放一个断点,
propertyInformationBindingSource.Filter
是什么样子?@Bala R对于Case“Banks”,它是“ClientKey='3',Search=-1”ClientKey的数据类型是什么?如果不是字符串,也许可以跳过单引号。否则,过滤器表达式对我来说很好。@Bala R我去掉了单引号。这似乎只适用于银行……其他一切都被忽略了。
propertyInformationBindingSource.Filter =
string.Format("ClientKey ='{0}' And Search = -1", comboBox1.SelectedValue);