Nils Olsson

Nils Olsson

  • NA
  • 16
  • 1.4k

How to combine 2 dataGridView filters

Mar 22 2018 5:56 PM
I have a Windows Form program in C#.
 
I have a dataGridView with several columns and where 2 columns are State and Country
 
I have 2 comboBoxes populated with all items from the State and County
 
 My code for the 2 filters are:
 
BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "[State] Like '%" + FilterState.Text + "%'" ;
dataGridView1.DataSource = bs;
 
BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "[Country] Like '%" + FilterCountry.Text + "%'";
dataGridView1.DataSource = bs;
 
 This 2 filters work OK separately, but I also need have both filters active together..
I am trying to make a combination of these 2 filters 
 
bs.Filter = "[State] Like '%" + FilterState.Text + "%'" AND "[Country] Like '%" + FilterCountry.Text + "%'"; 
 
 But, the line above is not working. How can I do it? Or must I have a totally different approach to ahve multiple filters
 
 

Answers (1)