Grouping In Datagrid In WPF


In this article we will see how to have Grouped rows in DataGrid In WPF.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as GroupingDataGridWPF.

First we need sample data to load into DataGrid, let’s have a Class called Employee which is having the following properties.

Now in the Constructor we will have some sample data and bind to DataGrid.

Now that we have Sample data let’s see how does it look like.

Looks good to proceed.

Now we will create a Style that will hold the Grouped Data.

To use it in DataGrid, use the following XAML inside DataGrid.

Now go back to C# code behind and add the Grouping definitions.

Now we are ready to test our application.

Yes, we have achieved grouping. Now we need to have Expand and Collapse functionality of the Group Header.

So in the Style defined for GroupItem let’s add an Expander control.

Now let’s test the application.

Now we can expand and collapse any Grouped Item.

Hope this article helps.


Related Posts:

1) Making Timeline Control for DataGrid In WPF

2) Custom Gridline Color of Datagrid In WPF

3) Custom Row and Header Height of Datagrid In WPF

4) Rounded Corner Datagrid In WPF

5) Tooltip In DataGrid In WPF

6) Cell Alignment In DataGrid In WPF

7) Edit Row Details In Context Menu In DataGrid In WPF

8) Hide/Un-Hide Columns Using Context Menu In DataGrid In WPF

9) Hide &Un-Hide DataGrid Column(s) In WPF

10) ComboBox In DataGrid In WPF

11) DatePicker In DataGrid In WPF

12) CRUD Operation In DataGrid In WPF