[英]C# 3 argument checkbox DataView.RowFilter Filtering with multiple columns
I have small problem, i dont know how realise more arguments filter. 我有一个小问题,我不知道如何实现更多参数过滤器。 I have 3 checkbox, Name, Category and Date(start,end) 我有3个复选框,名称,类别和日期(开始,结束)
Here is my code, individyaly for 1 check it work fine 这是我的代码,单独检查1可以正常工作
if (checkBox1.Checked == true)
{
views.RowFilter = "[Produkta nosaukums] like '%" + textBox3.Text.ToString() + "%'";
}
if (checkBox2.Checked == true)
{
views.RowFilter = "[Kateg.] like '%" + comboBox4.Text.ToString() + "%'";
}
if (checkBox3.Checked == true)
{
views.RowFilter = "[Derīguma termiņš] >= #" + dateTimePicker3.Value.ToString("yyyy/MM/dd") + "# and [Derīguma termiņš] <= #" + dateTimePicker4.Value.ToString("yyyy/MM/dd") + "#";
}
Problem is when i want more arguments search, like name and category. 问题是当我想搜索更多参数时,例如名称和类别。 I tryed here is my code, but only work for category name ignored :/ 我尝试过这里是我的代码,但只适用于类别名称被忽略的:/
if (checkBox1.Checked == false & checkBox2.Checked == false & checkBox3.Checked == false)
{
dataGridView1.Columns.Remove(editButton);
dataGridView1.Columns.Remove(deleteButton);
LOADALL();
}
if (checkBox1.Checked == true & checkBox2.Checked == true)
{
MessageBox.Show(comboBox4.Text.ToString());
MessageBox.Show(textBox3.Text.ToString());
views.RowFilter = "[Kateg.] like '%" + comboBox4.Text.ToString() + "%' and [Produkta nosaukums] like '%" + textBox3.Text.ToString() + "%'";
}
What i want is, filter add another checkbox too. 我想要的是,过滤器也添加另一个复选框。
Problem i dont know how combine :) tryed but dont worked :/ 问题我不知道如何结合:)尝试了但没有用:/
I would suggest using a stringBuilder in conjunction with your checkbox checks. 我建议结合使用stringBuilder和您的复选框检查。 for instance: 例如:
StringBuilder filter = new StringBuilder();
if(a.checked)
filter.Append("filter here");
if(b.checked)
filter.Append("filter here");
views.RowFilter= filter.toString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.