C# 如何在datagridview中从多个列中自动搜索?
我有一个文本框,显示datagrid中的行,datagrid将只显示与我键入的内容相关的行。 我这里有一个代码,但它只从“标题”栏搜索。我想要的是,它不仅会在“标题”栏中搜索,还会在“作者”和“姓名”栏中搜索。 以下是我得到的:C# 如何在datagridview中从多个列中自动搜索?,c#,C#,我有一个文本框,显示datagrid中的行,datagrid将只显示与我键入的内容相关的行。 我这里有一个代码,但它只从“标题”栏搜索。我想要的是,它不仅会在“标题”栏中搜索,还会在“作者”和“姓名”栏中搜索。 以下是我得到的: private void textBox1_TextChanged(object sender, EventArgs e) { DataView dv = new DataView(dt); dv.RowFilter = strin
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("Title LIKE '%{0}%'", txtsearch.Text);
dataGridView1.DataSource = dv;
}
试试这个:
dv.RowFilter = string.Format("Title LIKE '%{0}%' OR Author LIKE '%{0}%' OR Name LIKE '%{0}%'", txtsearch.Text);
然后更改过滤条件以包括这些条件,如下所示
dv.RowFilter = string.Format("Title LIKE '%{0}%' OR AUTHOR LIKE '%{0}%' OR Name LIKE '%{0}%'", txtsearch.Text);
您需要使用
或
dv.RowFilter = string.Format("Title LIKE '%{0}%' OR Author LIKE '%{0}%' OR Name LIKE '%{0}%'", txtsearch.Text);
有关更多信息,请访问。一些示例:@kielou,欢迎。。。考虑接受任何回答来表达你的感激之情。