如何使用文本框过滤datagridview并在C#中单击按钮? [英] How to filter datagridview with textbox and button click in C#?

查看:74
本文介绍了如何使用文本框过滤datagridview并在C#中单击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个解决方案但我无法弄清楚最终的代码。有人可以帮帮我吗?我想在单击没有数据库的按钮后按TextBox值过滤我的dataridView。所以一个非常简单的过滤器。



谢谢!



我的尝试:



I have found a solution but I can't figure out the final code. Anybody please can help me out? I want to filter my dataridView by TextBox value after clicking on the button without database. So a very simple Filter.

Thank you!

What I have tried:

private void FilterButton_Click(object sender, EventArgs e)
{
    DataTable dt = ((DataTable)DataGridView2.DataSource);
    foreach (DataGridViewRow row in DataGridView2.Rows)
    {
        // Test if the first column of the current row equals
        // the value in the text box
        if ((String)row.Cells["Month"].Value == birthdayMonth.Text)
        {
            // we have a match
            row.Selected = true;
        }
        else
        {
            row.Selected = false;

        }
    }
}

推荐答案

你应该去返回并查看其他解决方案。



您选择了最简单的答案,但也选择了零票答案。



您应该考虑下一页。



You should go back and review the "other" solution.

You picked the "easiest" answer but also the one with "zero votes".

You should probably consider the one "down a page".

Quote:

DataView dv =((DataTable)DataGridValue.DataSource).DefaultView;

dv.RowFilter =ColumnName< TB1 AND ColumName> TB2



然后将DataView绑定到gridView

DataView dv = ((DataTable)DataGridValue.DataSource).DefaultView;
dv.RowFilter = "ColumnName < TB1 AND ColumName > TB2"

Afterwards bind the DataView to your gridView





FROM



c# - 过滤DataGridView列中的数据行值,其值为两个文本框 - Stack Overflow [ ^ ]


这篇关于如何使用文本框过滤datagridview并在C#中单击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆