Skip to main content

PivotCustomFieldValueCellsEventArgsBase<T1, T2>.Split(Boolean, Predicate<T2>, Boolean, FieldValueSplitData[]) Method

Splits all field value cells that match the specified condition, or only the first matching cell.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.PivotGrid.v24.1.Core.dll

NuGet Packages: DevExpress.PivotGrid.Core, DevExpress.Win.Navigation

Declaration

public void Split(
    bool isColumn,
    Predicate<T2> match,
    bool firstCellOnly,
    params FieldValueSplitData[] cells
)

Parameters

Name Type Description
isColumn Boolean

true to process column field value cells; false to process row field value cells.

match Predicate<T2>

A System.Predicate that specifies the condition used to define which cells should be split.

firstCellOnly Boolean

true to split only the first cell that matches the specified condition; false to split all cells that match the condition.

cells FieldValueSplitData[]

The FieldValueSplitData objects that define how to split the cells.

Remarks

The Split method cannot split a field value cell if it has only one nested cell, or has none.

To split a cell (or several cells), create a System.Predicate<FieldValueCell> delegate that defines which cells should be split, and pass it as the match parameter. You also need to create a set of FieldValueSplitData objects. Each of them identifies a single new cell, from the leftmost to the rightmost (for column cells), or from the topmost to the bottommost (for row cells). Specify the size and values of the new cells using the FieldValueSplitData.NestedCellCount and FieldValueSplitData.Value properties, respectively, and pass the created objects as the cells parameter. The FieldValueSplitData.NestedCellCount property defines the size of a newly created cell by specifying the number of cells nested in it.

pivotgrid_splitdata

Example

The following example shows how to split the field value cells. In this example, the Grand Total column header is split into two cells: Price and Count. For this, the Split method of the CustomFieldValueCells event is used.

View Example: Pivot Grid for WinForms - Split Field Value Cells

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;
using DevExpress.XtraPivotGrid.Data;

namespace XtraPivotGrid_SplittingCells {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            pivotGridControl1.CustomFieldValueCells += 
                new PivotCustomFieldValueCellsEventHandler(pivotGrid_CustomFieldValueCells);
        }
        void Form1_Load(object sender, EventArgs e) {
            PivotHelper.FillPivot(pivotGridControl1);
            pivotGridControl1.DataSource = PivotHelper.GetDataTable();
            pivotGridControl1.BestFit();
        }
        protected void pivotGrid_CustomFieldValueCells(object sender,
                             PivotCustomFieldValueCellsEventArgs e) {
            PivotGridControl pivot = sender as PivotGridControl;
            if (pivot.DataSource == null) return;
            if (radioGroup1.SelectedIndex == 0) return;

            // Creates a predicate that returns true for the Grand Total headers, 
            // and false for any other column/row header.
            // Only cells that match this predicate are split.
            Predicate<FieldValueCell> condition =
                new Predicate<FieldValueCell>(delegate(FieldValueCell matchCell) {
                return matchCell.ValueType == PivotGridValueType.GrandTotal &&
                    matchCell.Field == null;
            });

            // Creates a list of cell definitions that represent newly created cells.
            // Two definitions are added to the list. The first one identifies the Price cell, 
            // which has two nested cells (the Retail Price and Wholesale Price
            // data field headers). The second one identifies the Count cell with 
            // one nested cell (the Quantity data field header).
            List<FieldValueSplitData> cells = new List<FieldValueSplitData>(2);
            cells.Add(new FieldValueSplitData("Price", 2));
            cells.Add(new FieldValueSplitData("Count", 1));

            // Performs splitting.
            e.Split(true, condition, cells);
        }
        void pivotGridControl1_FieldValueDisplayText(object sender, PivotFieldDisplayTextEventArgs e) {
            PivotGridControl pivot = sender as PivotGridControl;
            if (e.Field == pivot.Fields[PivotHelper.Month])
            {
                e.DisplayText = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName((int)e.Value);
            }
        }
        void radioGroup1_SelectedIndexChanged(object sender, EventArgs e) {
            this.pivotGridControl1.LayoutChanged();
        }        
    }
}
See Also