简体   繁体   English

DataGrid中的多列过滤器

[英]Multiple column filter in datagrid

I am able to filter data in datagrid based on one column at a time. 我能够一次基于一列过滤datagrid中的数据。 I want to filter data in datagrid based on two or more columns at a time. 我想一次基于两个或多个列来过滤datagrid中的数据。 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 . 问题在于了解为Filter构建字符串的语法。 You can simply add more properties to the Filter string like this: 您可以像这样简单地将更多属性添加到Filter字符串:

//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 . 有关可用于构建Filter字符串的内容的更多信息,请参见字符串表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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