c#Datagridview多个过滤器

时间:2013-10-31 14:24:50

标签: c# datagridview filter

我正在尝试使用两个或更多文本框过滤数据网格。 是否有一种简单的方法来启用它?现在,数据网格仅在最后检查的条件上进行过滤。

我整天搜索过,找不到解决方案。

这是两个盒子的代码。我在最后一个框中添加了两个过滤器,但这只是一个猜测,我知道它可能不起作用。

谢谢,A。

private void textBox4_TextChanged(object sender, EventArgs e)
    {
        BindingSource bs = new BindingSource();
        bs.DataSource = dataGridView1.DataSource;
        bs.Filter = "Bank like '%" + textBox4.Text + "%'";
        dataGridView1.DataSource = bs;
    }

    private void textBox5_TextChanged(object sender, EventArgs e)
    {
        BindingSource bs = new BindingSource();
        bs.DataSource = dataGridView1.DataSource;

        bs.Filter = "Bank like '%" + textBox4.Text + "%'";
        bs.Filter = "currency like '" + textBox5.Text + "'";

        dataGridView1.DataSource = bs;
    }

2 个答案:

答案 0 :(得分:1)

尝试这样的事情。

qualityBindingSource.Filter = string.Format("Date_ >= '{0}' AND Date_ <= '{1}'", dateTimePicker1.Text, dateTimePicker2.Text);

答案 1 :(得分:0)

BindingSource.DataSource创建新的DataView({DataTable})

BindingSource source1 = new BindingSource();
source1.DataSource = new DataView(ThreadModule.CaseManagerThread.caseListDataTable);
source1.Filter = "status = 0";
this.NewCaseTabControl.newCaseDataGridView.DataSource = source1;

BindingSource source2 = new BindingSource();
source2.DataSource = new DataView(ThreadModule.CaseManagerThread.caseListDataTable);
source2.Filter = "status = 1";
this.FinishCaseTabControl.finishCaseDataGridView.DataSource = source2;