I have small problem, i dont know how realise more arguments filter. I have 3 checkbox, Name, Category and Date(start,end)
Here is my code, individyaly for 1 check it work fine
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. for instance:
StringBuilder filter = new StringBuilder();
if(a.checked)
filter.Append("filter here");
if(b.checked)
filter.Append("filter here");
views.RowFilter= filter.toString();