简体   繁体   中英

Search bar for multiple columns in datagridview

I'm using a textbox to search a datagridview. But it only searches one column. I'd like to use it to search other columns as well. The code i'm currently using for the searchbar is:

private void autoZoeken_txt_TextChanged(object sender, EventArgs e)
{
    DataView DV = new DataView(dbdataset);
    DV.RowFilter = string.Format("kenteken LIKE '%{0}%'", autoZoeken_txt.Text);
    autoView_dgv.DataSource = DV;
}

You just need to modify the code to leverage the OR :

private void autoZoeken_txt_TextChanged(object sender, EventArgs e)
{
    DataView DV = new DataView(dbdataset);
    DV.RowFilter = string.Format(
        "kenteken LIKE '%{0}%' OR field2 LIKE '%{0}%'", autoZoeken_txt.Text);
    autoView_dgv.DataSource = DV;
}

and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM