Xceed Grid for WinForms v4.3 Documentation
What is a group?
Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Grid elements > What is a group?

A group is a collection of data rows that are combined automatically by matching field values or according to user-specified criteria. Groups are represented by the Group class. Grids created using Xceed Grid for WinForms can contain an unlimited number of nested group levels.

Grouping

Data bound rows can be grouped automatically or manually. To do automatic grouping, the GroupBy property of a group must be set to the field name of the column in the grid by which the data rows are to be grouped. To group the data rows manually, the QueryGroupKeys event can be used. This event can be used in conjunction with the GroupBy property to provide additional custom grouping criteria. 

Groups by themselves do not have a visual representation. In order for groups to have a visual representation, they usually contain at least one row that is not a data row in their header or footer sections. Typically, a GroupManagerRow is added to the header rows of a group to create an Outlook style grid. 

The example below demonstrates 2 ways in which groups can be created and added to the grid's collection of group templates:

C# Copy Code

Group group = new Group();
group.GroupBy = "ShipCountry";
group.HeaderRows.Add( new GroupManagerRow() ); 

gridControl1.GroupTemplates.Add( group );
gridControl1.GroupTemplates.Add( new Group( "ShipCity" ) ); 

// If you change the grouping after the data source was set, or data rows were
// added, you must call UpdateGrouping to refresh the groups. Ignore this line if
// you are creating group templates before setting the data source, or from inside
// a BeginInit() / EndInit() block.

gridControl1.UpdateGrouping();

 

Accessing individual groups

Groups can be accessed via the Groups property of both the GridControl class (which represents the grid) and the Group class (which represents a group). For example:

C# Copy Code

gridControl1.Groups[ 5 ].Collapse();
gridControl1.Groups[ 0 ].Groups[ 0 ].Expand();

Modifying grouping

The way in which the grid is grouped can be changed by modifying the group templates via the grid's GroupTemplates property. If the group templates are modified, the UpdateGrouping method must be called in order for the changes to be reflected in the grid.

Things you should consider

  • Do you want to provide custom grouping? Jump to the Custom Grouping topic.