Grouping refers to organizing the grid data into a hierarchical structure where rows with common column value are displayed as a group. The feature also lets you expand or collapse the groups to facilitate easier analysis of grid data.
In FlexGrid, grouping can be achieved through code as well as through user interaction via column context menu and FlexGridGroupPanel control. This topic discusses these ways and additional operations related to grouping.
FlexGrid provides GroupDescriptions property to describe how data source items are grouped in the grid. This property accepts the instance of any collection which implements IList interface (e.g. List) as its value. The items of the collection describe grouping using a property name as the criterion.
Following code shows how to apply grouping in the WinForms FlexGrid through code.
FlexGrid also lets you create groups at runtime using an extension control named C1FlexGridGroupPanel which is provided by the C1.Win.C1FlexGrid.GroupPanel assembly.
To achieve grouping in FlexGrid at runtime, add the C1FlexGridGroupPanel control to the form and bind it with the grid to be bound using FlexGrid property of the C1FlexGridGroupPanel class. Once a grid is bound to the group panel control, you can drag and drop the columns to panel in order to group the grid by that column. To create a nested hierarchy of dragged columns, you can drag multiple columns in the desired order. You can also set the maximum number of groups allowed within FlexGrid using MaxGroups property of the C1FlexGridGroupPanel class. By default, all the created groups appear in the expanded state. To change this setting and display the groups in collapsed state by default, you can set the AutoExpandAllGroups property to false. The group panel control also provides the Text property to display a string when no columns are dropped on the panel.
Use the code below to apply grouping in WinForms FlexGrid through the FlexGridGroupPanel control.
FlexGrid provides support for column context menu at run-time to facilitate quick actions related to column operations. One of these context menu options is Group By This Column. You can use this context menu option to group the grid data by any of the columns at run-time. Once grouping is applied, you also get the Ungroup option to remove grouping. To enable the column context menu, you need to set ColumnContextMenuEnabled property provided by the C1FlexGrid class to true. By default, this property is set to false.
Apart from the default features, grouping in FlexGrid comes with many other options to give you ample flexibility to meet your requirements.