【问题标题】:filter data in datagridview by using two column in one button通过一键使用两列过滤datagridview中的数据
【发布时间】:2014-08-22 07:48:40
【问题描述】:

如何通过在一个按钮中使用两列来过滤 datagridview 中的数据 我用这个代码

 private void button1_Click(object sender, EventArgs e)
    {
        BindingSource bs = new BindingSource();
        bs.DataSource = timerTryDataGridView.DataSource;
        bs.Filter = "Station like '%" + textBox1.Text + "%'";
        bs.Filter = "SEARIALNUM like '%" + textBox2.Text + "%'";
        timerTryDataGridView.DataSource = bs;
    }

但第二个过滤器取消第一个过滤器 我使用 C# 并访问数据库

任何帮助

【问题讨论】:

    标签: c# datagridview filter


    【解决方案1】:

    BindingSource.Filter 属性请参考MSDN Documentation

    要形成过滤器值,请指定列名,后跟 运算符和要过滤的值。接受的过滤器语法取决于 在基础数据源上。 如果基础数据源是 DataSet、DataTable 或 DataView,可以指定布尔表达式 使用为 DataColumn.Expression 属性记录的语法

    要在 DataGridView 上应用过滤器,有一种简单的方法,您可以应用行过滤器:

    string rowFilter = string.Format("Station LIKE '%{0}%' AND SEARIALNUM LIKE '%{1}%'",
                                      textBox1.Text, textBox2.Text);
    (timerTryDataGridView.DataSource as DataTable).DefaultView.RowFilter = rowFilter;
    

    【讨论】:

    • 我有这个消息语法错误消息('And' 运算符后缺少操作数。
    猜你喜欢
    • 1970-01-01
    • 2016-09-05
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多