Click here to Skip to main content
Licence CPOL
First Posted 14 Jun 2007
Views 48,554
Downloads 2,777
Bookmarked 52 times

Datagridview with filtering capability

By | 20 Jun 2007 | Article
Datagridview with filtering capability

Introduction

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" ?> 
<ColumnsToBeFiltered> 
<ColumnName>Branch</ColumnName> 
<ColumnName>City</ColumnName> 
</ColumnsToBeFiltered> 

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.

Assumptions

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

License

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

About the Author

Manas Bhardwaj

Technical Lead

Netherlands Netherlands

Member

Follow on Twitter Follow on Twitter
Manas Bhardwaj's Stream : www.manasbhardwaj.net

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionmulti select filter Pinmemberarkiboys23:53 1 Feb '12  
QuestionDatagridview filtering.dll PinmemberMaazatron3:01 14 Dec '11  
AnswerRe: Datagridview filtering.dll Pinmemberarkiboys23:56 1 Feb '12  
GeneralCountering thr rows PinmemberMember 299000810:18 28 Aug '10  
GeneralDynamic DataGridView filtering in C# PinmemberIvan (Zaragoza)22:50 3 Dec '08  
GeneralThis is a project Similar to MSDN: http://msdn.microsoft.com/en-us/library/aa480727.aspx PinmemberTamusRoyce10:29 13 Nov '08  
GeneralI am getting an error "Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataTable'." Pinmemberbondonian9:34 29 Sep '08  
GeneralI did some changes. post here to anyone interested Pinmemberzhngmm13:24 26 Aug '08  
GeneralRe: I did some changes. post here to anyone interested Pinmemberbondonian11:15 29 Sep '08  
GeneralRe: I did some changes. post here to anyone interested Pinmemberzhngmm17:23 29 Sep '08  
GeneralNice work PinmemberMohammad Dayyan3:56 16 Aug '08  
GeneralUse it in more than one datagridview Pinmemberdavomoreda0:08 6 May '08  
GeneralLooks Good but... PinmemberPat Tormey1:07 3 Jul '07  
GeneralDoe not work when using without data source. PinmemberNice Life1:39 15 Jun '07  
GeneralCant add it to my page Pinmemberdumty@gmail.com8:36 14 Jun '07  
GeneralRe: Cant add it to my page Pinmemberxadi1:28 19 Jun '07  
GeneralRe: Cant add it to my page PinmemberManas Bhardwaj1:36 19 Jun '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.5.120517.1 | Last Updated 20 Jun 2007
Article Copyright 2007 by Manas Bhardwaj
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid