Click here to Skip to main content
15,789,698 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I search through the internet how to filter data gridview using a textbox,
however it uses datasource

I dynamically bind the contents of my gridview,
is there a way to search through the gridview using textbox

Share this answer
Try with following findings,
BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "yourColumnName like '%" + textBox1.Text + "%'";
dataGridView1.DataSource = bs;

In Search Text Box Changed event, try the following,
(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("Field = '{0}'", searchTextBox.Text);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900