Datagridview行过滤器

时间:2016-01-04 05:42:38

标签: c# datagridview rowfilter defaultview

我正在使用RowFilterDataView dv = dt.DefaultView; if (e.KeyChar == (char)13) { dv.RowFilter = string.Format("Name LIKE '%{0}%'" ,textBox1.Text ); // dv.RowFilter = string.Format("Date LIKE '%{0}%'", textBox1.Text); } 。只有一列正在过滤, 但我希望过滤所有列。

我想在文本框中搜索一个单词来制作此过滤器。

name = Name

列标题为Datedetails,依此类推。

3 个答案:

答案 0 :(得分:1)

多列的格式应该是这样的;

dv.RowFilter = "Column1 = " + value1 + " AND Column2 = " + value2;

根据您的情景;

dv.RowFilter = string.Format("Name LIKE '%{0}%' AND Date = {1}" ,textBox1.Text, DateValue );

答案 1 :(得分:1)

(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("Name = '{0}'", TextBoxForSearch.Text);

答案 2 :(得分:0)

string query = textBox1.Text;
if(query == string.Empty)
{
    dataTable.DefaultView.RowFilter = string.Empty;
}
else
{
    (dgv.DataSource as DataTable).DefaultView.RowFilter = string.Format("Name = {0}", textBox1.Text);
    (dgv.DataSource as DataTable).DefaultView.RowFilter = string.Format("Date = {1}", textBox1.Text);
}