user2988642
user2988642

Reputation: 83

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;
}

Upvotes: 1

Views: 1281

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

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.

Upvotes: 5

Related Questions