Arun Agarwal
Arun Agarwal

Reputation: 795

Filter rows in datagridview in C#.net windows application

How to filter rows in datagridview C#.net windows application , as we write text in the textbox at runtime the filtered rows should appear in the datgridview

Upvotes: 1

Views: 2364

Answers (2)

PHBeagle
PHBeagle

Reputation: 122

On your textbox, create a method for the "TextChanged" event that calls your query method. Similar to this:

private void btnFilter_Click(object sender, EventArgs e)
{
    GetData();
}

GetData is your method that retrieves data from your database.

Upvotes: 0

Łukasz Motyczka
Łukasz Motyczka

Reputation: 1199

This did work for me:

BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = sColumnaDoPrzeszukania + " like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = bs;

The whole question is here: How to filter a datagridview by a textbox after loading an excel file into it

Upvotes: 1

Related Questions