Click here to Skip to main content
Click here to Skip to main content

Datagridview with filtering capability

, 20 Jun 2007
Rate this:
Please Sign up or sign in to vote.
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
Architect
Netherlands Netherlands
Read my personal blog at www.manasbhardwaj.net.
Follow on   Twitter

Comments and Discussions

 
Questionnot sure what I'm doing wrong Pinmemberesb7718-Jun-13 9:55 
GeneralMy vote of 5 PinmemberDigitalGeek21-Nov-12 23:36 
GeneralRe: My vote of 5 PinmemberManas Bhardwaj21-Nov-12 23:43 
GeneralRe: My vote of 5 PinmemberDigitalGeek22-Nov-12 2:16 
QuestionA Good Solution also Pinmemberhusain300610-Oct-12 6:38 
Questionthere is a problem with VS 2010 Pinmemberesb776-Oct-12 14:20 
AnswerRe: there is a problem with VS 2010 Pinmemberesb777-Oct-12 5:59 
GeneralRe: there is a problem with VS 2010 PinmemberManas Bhardwaj7-Oct-12 6:42 
Questionmulti select filter Pinmemberarkiboys1-Feb-12 23:53 
QuestionDatagridview filtering.dll PinmemberMaazatron14-Dec-11 3:01 
AnswerRe: Datagridview filtering.dll Pinmemberarkiboys1-Feb-12 23:56 
GeneralCountering thr rows PinmemberMember 299000828-Aug-10 10:18 
GeneralDynamic DataGridView filtering in C# PinmemberIvan (Zaragoza)3-Dec-08 22:50 
GeneralThis is a project Similar to MSDN: http://msdn.microsoft.com/en-us/library/aa480727.aspx PinmemberTamusRoyce13-Nov-08 10:29 
GeneralI am getting an error "Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataTable'." Pinmemberbondonian29-Sep-08 9:34 
GeneralI did some changes. post here to anyone interested Pinmemberzhngmm26-Aug-08 13:24 
GeneralRe: I did some changes. post here to anyone interested Pinmemberbondonian29-Sep-08 11:15 
GeneralRe: I did some changes. post here to anyone interested Pinmemberzhngmm29-Sep-08 17:23 
GeneralUse it in more than one datagridview Pinmemberdavomoreda6-May-08 0:08 
GeneralLooks Good but... PinmemberPat Tormey3-Jul-07 1:07 
GeneralDoe not work when using without data source. PinmemberNice Life15-Jun-07 1:39 
GeneralCant add it to my page Pinmemberdumty@gmail.com14-Jun-07 8:36 
GeneralRe: Cant add it to my page Pinmemberxadi19-Jun-07 1:28 
GeneralRe: Cant add it to my page PinmemberManas Bhardwaj19-Jun-07 1:36 

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.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 20 Jun 2007
Article Copyright 2007 by Manas Bhardwaj
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid