Pregunta

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.

  1. Check1, check2, check3
  2. true true true dont realized
  3. true false true dont realized
  4. false true true dont realized
  5. true true false dont work tryed
  6. true false false work
  7. false true false work
  8. false false true work
  9. false false false work

Problem i dont know how combine :) tryed but dont worked :/

¿Fue útil?

Solución

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();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top