Bindingsource.filter 中的多个条件存在问题
我正在尝试根据 2 个组合框过滤绑定源。我有一个组合框过滤器就很好。第二个让我感到困惑,因为它使用第一个组合框,然后使用基于 switch 语句的第二个组合框:
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;
}
}
我对 AND 之后的值遇到问题,其中它声称是错误的。任何帮助都会很棒。
谢谢
I am trying to filter a binding source based on 2 comboboxes. I have one of comboboxes filter just fine. The second has me stumped as it uses the first combobox and then the second based on a switch statement:
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;
}
}
I am having issues with the value after the AND in which it claims is wrong. Any help would be great.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为存在一些字符串连接问题,并且您缺少
Finisher = -1
周围的右括号。请
注意,如果进行太多字符串连接,最好使用
string.Format()
。它提高了可读性并且比串联更有效。例如,您的第一个案例如下所示I think there were some string concatenation issues and you were missing the closing parenthesis around
Finisher = -1
.Try
Note if you have too much string concatenation going on, it's best that you use
string.Format()
. It improves readability and is more efficient that concatenation. As an example, you first case would look like this