Back to Devexpress

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

corelibraries-devexpress-dot-xtrapivotgrid-dot-pivotcustomfieldvaluecellseventargsbase-2-dot-split-x28-system-dot-boolean-system-dot-predicate-1-system-dot-boolean-devexpress-dot-xtrapivotgrid-dot-data-dot-fieldvaluesplitdata-x29.md

latest10.1 KB
Original Source

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.v25.2.Core.dll

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

Declaration

csharp
public void Split(
    bool isColumn,
    Predicate<T2> match,
    bool firstCellOnly,
    params FieldValueSplitData[] cells
)
vb
Public Sub Split(
    isColumn As Boolean,
    match As Predicate(Of T2),
    firstCellOnly As Boolean,
    ParamArray cells As FieldValueSplitData()
)

Parameters

NameTypeDescription
isColumnBoolean

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.

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

csharp
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();
        }        
    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid
Imports DevExpress.XtraPivotGrid.Data

Namespace XtraPivotGrid_SplittingCells
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
            AddHandler pivotGridControl1.CustomFieldValueCells, AddressOf pivotGrid_CustomFieldValueCells
        End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            PivotHelper.FillPivot(pivotGridControl1)
            pivotGridControl1.DataSource = PivotHelper.GetDataTable()
            pivotGridControl1.BestFit()
        End Sub
        Protected Sub pivotGrid_CustomFieldValueCells(ByVal sender As Object,
                                ByVal e As PivotCustomFieldValueCellsEventArgs)
            If pivotGridControl1.DataSource Is Nothing Then
                Return
            End If
            If radioGroup1.SelectedIndex = 0 Then
                Return
            End If

        ' 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.
            Dim condition As New Predicate(Of FieldValueCell)(Function(matchCell As FieldValueCell) matchCell.ValueType =
                                                PivotGridValueType.GrandTotal AndAlso matchCell.Field Is Nothing)

            ' 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).
            Dim cells As New List(Of FieldValueSplitData)(2)
            cells.Add(New FieldValueSplitData("Price", 2))
            cells.Add(New FieldValueSplitData("Count", 1))

            ' Performs splitting.
            e.Split(True, condition, cells)
        End Sub
        Private Sub pivotGridControl1_FieldValueDisplayText(ByVal sender As Object,
                                ByVal e As PivotFieldDisplayTextEventArgs) Handles pivotGridControl1.FieldValueDisplayText
            Dim pivot As PivotGridControl = TryCast(sender, PivotGridControl)
            If e.Field Is pivot.Fields(PivotHelper.Month) Then
                e.DisplayText = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(CInt((e.Value)))
            End If
        End Sub
        Private Sub radioGroup1_SelectedIndexChanged(ByVal sender As Object,
                                ByVal e As EventArgs) Handles radioGroup1.SelectedIndexChanged
            Me.pivotGridControl1.LayoutChanged()
        End Sub
    End Class
End Namespace

See Also

PivotCustomFieldValueCellsEventArgsBase<T1, T2> Class

PivotCustomFieldValueCellsEventArgsBase<T1, T2> Members

DevExpress.XtraPivotGrid Namespace