[英]How can i auto search from multiple column in my datagridview?
我有一個文本框,顯示數據網格中的行,數據網格只顯示與我輸入的內容相關的行。我這里有一個代碼,但它只搜索“標題”列。 我想要的是它不僅會搜索“標題”列,還會搜索“作者”和“名稱”列。 這是我得到的:
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);
你需要使用OR
dv.RowFilter = string.Format("Title LIKE '%{0}%' OR Author LIKE '%{0}%' OR Name LIKE '%{0}%'", txtsearch.Text);
可以在MSDN上找到更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.