I see in this video its quite easy to add a textbox and have it drive the filtering of a datagridView. The issue is in this video it seems you have to specific which column to filter based on.
RowFilter = "FirstName like "%' + searchText.Text + '%"
but what if I want it to check all of the fields and show the row if any column has my search string in it
You would want to loop through each column in your row and append an OR comparison
This is really stupid code, but hopefully gives you the gist of it. Something like:
StringBuilder filter = new StringBuilder();
foreach(var column in dataGridView.Columns)
{
if(filter.ToString() == "")
{
filter.Append(column.Name + " like '" + searchText.Text + "'");
}
else
{
filter.Append(" OR ");
filter.Append(column.Name + " like '" + searchText.Text + "'");
}
}
RowFilter = filter.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With