如何使用文本框过滤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".
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 [ ^ ]