How to: Implement Custom Group Intervals

  • 2 minutes to read

This example shows how to provide a custom criteria used to group axis values. The Pivot Grid Control contains two row fields bound to the same ProductName data source field, named Product Group and Product respectively. The custom grouping is applied to the first field and combines the first field’s values by the starting characters of values into three large ranges: A-E, F-S, and T-Z.

The Product Group field’s PivotGridFieldBase.GroupInterval property is set to Custom at design-time. The grouping logic is implemented by handling the PivotGridControl.CustomGroupInterval event.


using System.Windows.Forms;
using System;

namespace WindowsApplication {
    public partial class Form1 : Form {
        public Form1() {
            pivotGridControl1.CustomGroupInterval += pivotGridControl1_CustomGroupInterval;
        protected void pivotGridControl1_CustomGroupInterval(object sender, 
        PivotCustomGroupIntervalEventArgs e) {
            if (e.Field.Caption != "Product Group") return;

            if (Convert.ToChar(e.Value.ToString()[0]) < 'F') {
                e.GroupValue = "A-E";

            if (Convert.ToChar(e.Value.ToString()[0]) > 'E' && 
            Convert.ToChar(e.Value.ToString()[0]) < 'T') {
                e.GroupValue = "F-S";

            if (Convert.ToChar(e.Value.ToString()[0]) > 'S')
                e.GroupValue = "T-Z";