简体   繁体   中英

Multiple column filter in datagrid

I am able to filter data in datagrid based on one column at a time. I want to filter data in datagrid based on two or more columns at a time. currently i am using

BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "[Branch]='" + comboBox3.Text.ToString()+ "'";
dataGridView1.DataSource = bs.DataSource;

The problem is understanding the syntax to build the string for Filter . You can simply add more properties to the Filter string like this:

//for 3 columns
bs.Filter = "[Column1] = 'Value1' AND [Column2] = 'Value2' AND [Column3] = 'Value3'";

More info about possible stuff you can use to build a Filter string can be found here string expression .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM