Field Groups

  • 3 minutes to read

The Pivot Grid provides the capability to arrange fields into groups. End-users cannot separate grouped fields by dragging one of them to a different area or by hiding it in the field list.

pivotgrid_groups

TIP

Demo: Groups

Requires installation of WPF Subscription. Download.

Create a Field Group

Do the following to create a new group:

  1. Create a PivotGridGroup descendant and add it to the PivotGridControl.Groups collection, which stores the Pivot Grid's field groups.
  2. You can define a new group in two ways:

  3. Set the PivotGridField.GroupIndex property to specify a field's index in the group.

Field Group Settings

To move a group to a specific area or new position within the current area, use the PivotGridField.Area and PivotGridField.AreaIndex properties of the first field in the group. Setting these properties for the second and subsequent fields in the group has no effect.

A Group Expand button allows you to collapse and expand the grouped field. Collapsing/expanding a grouped field header hides/shows columns or rows that correspond to grouped child fields.

pivotgrid_collapsegroups

To set the expansion status of grouped fields in code, use the PivotGridField.ExpandedInFieldsGroup property.

Member Table

Property Description
PivotGridControl.Groups Gets the collection of field groups.
PivotGridField.Group Gets or sets the group which owns the current field.
PivotGridField.GroupName Gets or sets the group name of the current field.
PivotGridField.GroupIndex Gets or sets the field's index in a group.
PivotGridField.ExpandedInFieldsGroup Gets or sets the current field's expansion status it belongs to a group.

Example: How to Arrange Fields into a Group

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

In this example, two fields ("Country" and "Customer") are combined into a new group at design time, and another two fields ("Category" and "Product") are combined into a new group at runtime, in this order. This ensures that the "Country" field is followed by "Customer", and the the "Category" field is followed by "Product". If you drag the "Region" field and drop it to another area, the "Customer" field accompanies it. This behavior is also true for the second group.

NOTE

A complete sample project How to: Group Fields is available at GitHub.

using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.DataSet1TableAdapters;
using static HowToBindToMDB.DataSet1;

namespace HowToBindToMDB {
    public partial class MainWindow : Window {
        SalesPersonDataTable salesPersonDataTable = 
            new SalesPersonDataTable();
        SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();
        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = salesPersonDataTable;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e) {
            salesPersonDataAdapter.Fill(salesPersonDataTable);

            // Create a group at run-time
            PivotGridGroup group = pivotGridControl1.Groups.Add(fieldCategoryName, fieldProductName);
        }
    }
}