Sep 6, 2011

FilterableDataGridView (C#.NET): A DataGridView control with built-in Filtering

During developing my project I was left without Internet access for a week, and I couldn't search for an easy and already written solution for my problem, so I decided to create my own solution.

I had a DataGridView on one of my forms with a DataSource linked to an SQL server through LINQ to SQL and I wanted to be able to filter the result rows, based on user input. Since the clients (the users of my program) will connect to the database through the Internet, some of them via poor connections, I didn't want to make a new query with each change of the filter. I found out that the DataGridViewRow has a Visible property, and it looked like an efficient way to set this according to the filters. So I created a new class inheriting from the DataGridView, and added some extra functionality to support filtering.