Field Groups

  • 3 minutes to read

The PivotGridControl allows you to arrange its fields into groups. End-users cannot separate such fields by dragging one of them to a different area or hiding it in the customization form.

TIP

Demo: Groups module in the XtraPivotGrid MainDemo

Requires installation of WinForms Subscription. Download.

Field Groups

Fields can be arranged into groups stored in the PivotGridControl.Groups collection. To move a group to a specific area or to a new position within the current area, use the PivotGridFieldBase.Area and PivotGridFieldBase.AreaIndex properties of the first field in the group. Modifying these properties for the second and subsequent fields in the group will have no effect.

Grouped fields can be collapsed and expanded by clicking the expand buttons. Collapsing/expanding a grouped field header collapses/expands columns or rows that correspond to grouped child fields. The PivotGridFieldBase.ExpandedInFieldsGroup property allows you to get or modify the expansion status of grouped fields in code.

cdFieldsLocation2

Group Values

A group value is an ordered set of values (from fields) arranged into a group. For instance, the "Year - Quarter - Month" field group in the image below contains the "1996 - Quarter 3 - September", "1994 - Quarter 3 - August" and "1994 - Quarter 4" group values.

Group values may include values from all fields in the group (like the "1994 - Quarter 3 - August" group value from the example above), or from only several of them (the "1994 - Quarter 4" group value). In the latter instance, the group value has a set of child values. In the PivotGridControl shown in the image below, the "1994 - Quarter 4" group value has the 'October', 'November' and 'December' child values.

pivotgrid_groupvalues

Use the PivotGridGroup.GetUniqueValues method to obtain child values from a particular group value.

Example: How to Group Fields

The following example demonstrates how to combine fields into a group.

In the example three fields ('Country', 'Region' and 'City') are combined into a new group in that order. This ensures that the 'Country' field will be followed by 'Region' which is in turn followed by 'City'. If the 'Region' field is being dragged to another area the other fields will be dragged as well. The following image shows the 'Region' field being dragged to the Filter Header Area.

PivotGridControl_Groups

using DevExpress.XtraPivotGrid;

PivotGridField fieldCountry = pivotGridControl1.Fields["Country"];
PivotGridField fieldRegion = pivotGridControl1.Fields["Region"];
PivotGridField fieldCity = pivotGridControl1.Fields["City"];
// Add a new group which combines the fields.
pivotGridControl1.Groups.Add(new PivotGridField[] {fieldCountry, fieldRegion, fieldCity});
See Also