IntroductionIn this article we will see how to have Grouped rows in DataGrid in WPF.Crating WPF Application ProjectFire 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.
C# Corner. All contents are copyright of their authors.