Skip to main content
Email Password   helpLost your password?

Note: The Visual Studio solution contains a project named GridExtensionUnitTests which requires NUnit to compile. If you don't have NUnit then just remove it from the solution - it is not required if you just want to use the grid.

Contents

Introduction

With the DataGrid, Microsoft has provided a very mighty grid control which has some excellent features. With the possibility to easily add DataViews and customize visualization, the DataGrid is for sure one of the most important controls in the .NET Framework.

This component further extends the functionality of the DataGrid by adding filtering capabilities in an easy, automated and customizable way. The functionality goes beyond the requirements I had in my special case. But I thought it might be a good idea to make something sophisticated which can be used at various places.

Background

Before reading this article, you should know the basics of working with the DataGrid. That's all you need to use this article. To better understand the technical background, you should also be familiar with the concepts of DataViews, RowFilter and DataGridTableStyles.

Using the code

There are three ways of using this component:

All the three ways are shown in the included examples.

Samples

I have put much effort in supplying good samples in the downloads. They cover most of the functionality of this component, so if you want to know what this grid is capable of then play around with them. They depend on the MSAccess Northwind database which can be freely downloaded from Microsoft. At the top of the article you will find a direct download link to this. For easier usage it is also contained in one of the demo project downloads.

Architecture

Overview

Internally the most important class is the GridFiltersControl. It builds up the filter criteria and contains the filter controls (unless they are customized). Most of the functionality is placed within it. Then there is the DataGridFilterExtender which binds a DataGrid or ExtendedDataGrid to a GridFiltersControl. How the columns are filtered and what GUI has to be shown is defined in the IGridFilter implementations which are created by an IGridFilterFactory. The FilterableDataGrid class is finally a composition of all those classes which allows a quick start.

The following sections contain some more information on the classes within this component. For a more detailed information just look at the fully commented code or have a look into the compiled help file contained in the downloads.

ExtendedDataGrid

This class is derived from DataGrid. Its main extension is that it provides a property AutoCreateTableStyles to automatically create table styles. This is done whenever the DataSourceChanged event occurs and no appropriate table style is found. Furthermore, it publishes some protected properties from the DataGrid which are normally not accessible from outside.

IGridFilter

This is the basic interface describing how a column can be filtered. For this it defines the GUI elements and the textual representations of the filter criteria.

IGridFilter implementations

All the given implementations of IGridFilter derive from the abstract class GridFilterBase, which is like all the concrete implementations located in the GridExtensions.GridFilters namespace. When making your own filters I would recommend using this base class as it reduces the amount of work to be done to get a working filter.

I have provided the following implementations of the IGridFilter:

IGridFilterFactory

This is a simple interface which provides a method to create an IGridFilter for a specified column. I included this interface to provide maximum flexibility. It could, for example, be used to specify special filters for each column separately.

Instead of having to implement your own IGridFilterFactory for every special case, it is also possible to extend an existing implementation by binding its GridFilterCreated event. It provides information about the table, name and the type of the column for which an IGridFilter is being created and also the instance provided by the factory. The handler of the event can then exchange the IGridFilters for the needed columns. This is, for example, useful when you want to define an EnumerationGridFilter with a customized IntStringMapEnumerationSource to a special column while leaving all other columns as they are.

IGridFilterFactory implementations

Three implementations of this interface are provided within this component (all are located in the GridExtensions.GridFilterFactories namespace). Another one can be found in the samples. They not only provide how the columns are filtered but also where the filtering GUI is located. The included implementations are:

GridFiltersControl

This internal class should be of no matter to you if you are only using this library. This is the control which is placed above, beyond or within the DataGrid which is extended. It holds all the extra controls from the current IGridFilters which have not set its UseCustomPlacement property to true. It also contains most of the filter building logic of this component.

DataGridFilterExtender

Now we come to the core class of the library. I have documented all the public properties and methods very well so I won't go too far into the details here. The most important properties are:

All other properties can be explored by yourselves.

FilterableDataGrid

This control is nothing more than a UserControl which binds the ExtendedDataGrid and the DataGridFilterExtender together. For every new filterable grid you want to create, this should do the job without having to handle several components.

DataGridView

I finally made a DataGridView version of this component which is called DataGridViewExtensions. The solution is logically a Visual Studio 2005 solution while the DataGrid solution is still 2003. It has most of the functionality of the original component. The missing parts and known issues are:

ToDo's

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralAdd ShowHiddenColumns Property To LayoutedGridFilterFactoryControl Pin
Polymorpher
11:12 29 Sep '09  
GeneralSet the default value of a filter [modified] Pin
antal_szilard
1:04 31 Aug '09  
GeneralFiltertyp bearbeiten Pin
Member 823346
23:27 16 Jul '09  
Generalplz help more Pin
maedeh_22
23:47 8 Jun '09  
QuestionSave Filtered Data from the Grid to DataBase. Pin
rish7
0:42 22 May '09  
GeneralIs there any way to hide a column after assigning dataset Pin
ramesh_cnj
1:16 19 May '09  
Generaldatagridview combobox column Pin
Tabitutza
2:32 30 Apr '09  
GeneralRe: datagridview combobox column Pin
Jamie Nordmeyer
7:07 16 Jun '09  
General[Message Deleted] Pin
Tabitutza
21:39 16 Jun '09  
GeneralRe: datagridview combobox column Pin
Jamie Nordmeyer
5:40 17 Jun '09  
GeneralRe: datagridview combobox column Pin
Tabitutza
5:44 17 Jun '09  
QuestionHow can I change the Checkbox from being three-state to just two-state? [modified] Pin
djMcCauley
13:15 28 Apr '09  
QuestionProblem: the arrow in the caption bar is missing? (used to move back up the hierarchy of table views) Pin
djMcCauley
9:24 13 Mar '09  
AnswerRe: Problem: the arrow in the caption bar is missing? (used to move back up the hierarchy of table views) Pin
Robert Rohde
9:09 15 Mar '09  
QuestionRe: Problem: the arrow in the caption bar is missing? (used to move back up the hierarchy of table views) [modified] Pin
djMcCauley
12:22 16 Mar '09  
AnswerRe: Problem: the arrow in the caption bar is missing? (used to move back up the hierarchy of table views) Pin
Robert Rohde
11:31 17 Mar '09  
GeneralRe: Problem: the arrow in the caption bar is missing? (used to move back up the hierarchy of table views) Pin
djMcCauley
17:05 17 Mar '09  
GeneralI hope it works cool too Pin
Vincenzo Rossi
7:22 4 Mar '09  
Generalany updates ?? Pin
alhambra-eidos
2:41 11 Feb '09  
GeneralReza Thanks Robert Pin
BABABIKHIAL
22:43 2 Jan '09  
GeneralRequery Server Data Pin
mapner
5:01 24 Dec '08  
QuestionEditing Filtered Column Pin
kjward
5:01 23 Dec '08  
AnswerRe: Editing Filtered Column Pin
kjward
7:05 23 Dec '08  
GeneralWhat happened with idea to print DataGrid ?! Pin
Ivan Vujic
3:39 14 Oct '08  
GeneralImproved EnumerationGridFilter Pin
Arikael
23:27 17 Sep '08  


Last Updated 20 Nov 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009