Click here to Skip to main content
13,899,986 members
Click here to Skip to main content
Add your own
alternative version


63 bookmarked
Posted 14 Jun 2007
Licenced CPOL

Datagridview with filtering capability

, 20 Jun 2007
Rate this:
Please Sign up or sign in to vote.
Datagridview with filtering capability


The Microsoft Windows Forms Datagridview provided with the MS Visual Studio 2005 has got a lot new and good features which were missing in the datagrid control provided in the earlier versions of MS .Net. But still, many times the developers or I should say the functional need of the application require the filtering capabilities.

In this article, I am gonna explain the method by which we can add the filtering capabilities in the Datagridview header itself.

To just start with and summarize, it can be entirely customized through an xml file and decided to which of columns, the filtering capability is to be provided.

Unlike most of the filtering grids available, it allows you to apply filter on more than one filter at a time and in that too, you can select multiple values in a column. Thus extending the feature for searching/filtering or we should say minimizing the desired view of data to the bare minimum level. Screenshot - 1.jpg

Screenshot - 2.jpg

Using the code

FilterDataGridView is a fully customizable user control. As far as the developer's point of view is concerned. He will not have to make a single line of code change in his code and yet he can achieve the filtering capability. J

As many of the times, we don't want to give the filtering capability to all the columns that why FilterDataGridView reads the name of the columns from an xml file which have to be enabled for the filtering.

That means what all one developer has to do is to provide an xml file with the name of the columns to be filtered.

Below, I have mentioned what all steps would need to be taken if you want to replace the old Datagridview with the FilterDataGridView.

  1. Add a reference to the FilteredGridViewControl.dll in your project and also add it to your toolbar.
  2. Drag the FilteredGridView from your toolbar to the window form as you do with any other control.
  3. Add FilterGridView.xml to your application. In the compile property, set the Copy to Output folder option.

This xml should look like this:

<?xml version="1.0" encoding="utf-8" ?> 

You can specify as many columns here which are to be filtered.

And here we go, all is set. Wasn't that simple?

How it works?

With FilteredGridView, when you right click on a header of a column which is there in the list of Columns to be filtered, it will list all the distinct rows. Now you can select any of the row it your grid will automatically be filtered with that value. FilteredGridView supports applying multiple filters on a single column. That means you can apply as many filters on a column and at the same time you can narrow the data by putting filters on other columns data too.


This version of FilterGridView only works when bound with a Data Source.


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


About the Author

Manas Bhardwaj
Netherlands Netherlands

Read my personal blog at

You may also be interested in...

Comments and Discussions

Questiondownload not working Pin
Member 139440729-Aug-18 19:24
memberMember 139440729-Aug-18 19:24 
QuestionDropdown columns Pin
sridharsr23-Aug-14 6:25
membersridharsr23-Aug-14 6:25 
Questionnot sure what I'm doing wrong Pin
esb7718-Jun-13 9:55
memberesb7718-Jun-13 9:55 
GeneralMy vote of 5 Pin
Digital Geek21-Nov-12 23:36
memberDigital Geek21-Nov-12 23:36 
GeneralRe: My vote of 5 Pin
Manas Bhardwaj21-Nov-12 23:43
professionalManas Bhardwaj21-Nov-12 23:43 
GeneralRe: My vote of 5 Pin
Digital Geek22-Nov-12 2:16
memberDigital Geek22-Nov-12 2:16 
QuestionA Good Solution also Pin
code-kings10-Oct-12 6:38
membercode-kings10-Oct-12 6:38 
Questionthere is a problem with VS 2010 Pin
esb776-Oct-12 14:20
memberesb776-Oct-12 14:20 
AnswerRe: there is a problem with VS 2010 Pin
esb777-Oct-12 5:59
memberesb777-Oct-12 5:59 
GeneralRe: there is a problem with VS 2010 Pin
Manas Bhardwaj7-Oct-12 6:42
professionalManas Bhardwaj7-Oct-12 6:42 
Questionmulti select filter Pin
arkiboys1-Feb-12 23:53
memberarkiboys1-Feb-12 23:53 
QuestionDatagridview filtering.dll Pin
Maazatron14-Dec-11 3:01
memberMaazatron14-Dec-11 3:01 
AnswerRe: Datagridview filtering.dll Pin
arkiboys1-Feb-12 23:56
memberarkiboys1-Feb-12 23:56 
GeneralCountering thr rows Pin
Member 299000828-Aug-10 10:18
memberMember 299000828-Aug-10 10:18 
GeneralDynamic DataGridView filtering in C# Pin
Ivan (Zaragoza)3-Dec-08 22:50
memberIvan (Zaragoza)3-Dec-08 22:50 
GeneralThis is a project Similar to MSDN: Pin
TamusRoyce13-Nov-08 10:29
memberTamusRoyce13-Nov-08 10:29 
GeneralI am getting an error "Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataTable'." Pin
bondonian29-Sep-08 9:34
memberbondonian29-Sep-08 9:34 
GeneralI did some changes. post here to anyone interested Pin
zhngmm26-Aug-08 13:24
memberzhngmm26-Aug-08 13:24 
GeneralRe: I did some changes. post here to anyone interested Pin
bondonian29-Sep-08 11:15
memberbondonian29-Sep-08 11:15 
GeneralRe: I did some changes. post here to anyone interested Pin
zhngmm29-Sep-08 17:23
memberzhngmm29-Sep-08 17:23 
GeneralNice work Pin
Mohammad Dayyan16-Aug-08 3:56
memberMohammad Dayyan16-Aug-08 3:56 
GeneralUse it in more than one datagridview Pin
davomoreda6-May-08 0:08
memberdavomoreda6-May-08 0:08 
GeneralLooks Good but... Pin
Pat Tormey3-Jul-07 1:07
memberPat Tormey3-Jul-07 1:07 
GeneralDoe not work when using without data source. Pin
Joe Sonderegger15-Jun-07 1:39
memberJoe Sonderegger15-Jun-07 1:39 
GeneralCant add it to my page Pin
DumtySoft14-Jun-07 8:36
memberDumtySoft14-Jun-07 8:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 20 Jun 2007
Article Copyright 2007 by Manas Bhardwaj
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid