Thursday, July 19, 2012

WPF DataGridGrouping

For those of you that do not have access to some of the better .Net Grid controls here is a simple overview on the WPFToolKit DataGrid Grouping. For some reason this took me a little longer to figure than I thought it should have.

We have three primary components to make the grouping happen. Style, GroupStyle and ListCollectionView.

First is the Window.Resource or Style:
 This should be placed above the Grid node in your window. This will create the Style that will hold the Grouped Date.


WPFGrouping9.gif

Next we need GroupStyle in the actual DataGrid:
 Place this below the DataGrid Properties and above the DataGrid Columns

WPFGrouping6.gif

Finally you need to load a new GroupDescription with a ListCollectionView
The below method is called on load and the ListCollectionView allows you to have a GroupDescription.Add which sets up your DataGridGroup
.


Example:


In my finally example, I have added an expander that allows me to expand and collapse on the grouped field in the DataGrid. Seems like a pretty simple task but for some reason I had a hard time figuring this one out. 

Posted Code Sample:
WPFCRUDGrouping






0 comments:

Post a Comment