Back to Devexpress

PivotCustomFieldValueCellsEventArgs.Split(Boolean, Predicate<FieldValueCell>, Boolean, IList<FieldValueSplitData>) Method

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotcustomfieldvaluecellseventargs-dot-split-x28-boolean-predicate-fieldvaluecell-boolean-ilist-fieldvaluesplitdata-x29.md

latest11.1 KB
Original Source

PivotCustomFieldValueCellsEventArgs.Split(Boolean, Predicate<FieldValueCell>, Boolean, IList<FieldValueSplitData>) Method

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

Namespace : DevExpress.Xpf.PivotGrid

Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public void Split(
    bool isColumn,
    Predicate<FieldValueCell> match,
    bool firstCellOnly,
    IList<FieldValueSplitData> cells
)
vb
Public Sub Split(
    isColumn As Boolean,
    match As Predicate(Of FieldValueCell),
    firstCellOnly As Boolean,
    cells As IList(Of FieldValueSplitData)
)

Parameters

NameTypeDescription
isColumnBoolean

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

| | match | Predicate<FieldValueCell> |

A System.Predicate that represents 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 | IList<FieldValueSplitData> |

A list of 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 should also create a list of FieldValueSplitData objects. Each of them identifies a single new cell, from the leftmost to the rightmost (for the column cells), or from the topmost to the bottommost (for the row cells). Specify the size and values of the new cells using the FieldValueSplitData.NestedCellCount and FieldValueSplitData.Value properties, respectively, and pass the list 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 demonstrates how to split field value cells. In this example, the Grand Total column header is split into two cells: Price and Count.

View Example

Handle the CustomFieldValueCells event and call the event parameter’s Split method. Cells that should be split are identified by a predicate that returns true for those cells. The quantity, size, and captions of newly created cells are specified by an array of cell definitions (the FieldValueSplitData objects).

xaml
<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        x:Class="DXPivotGrid_SplittingCells.Window1" 
        dx:ThemeManager.ThemeName="LightGray" 
        Height="580" Width="1200"
        Loaded="Window_Loaded"
        Title="Window1">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <dxpg:PivotGridControl Grid.Row="1" Margin="2,2,2,0" Name="pivotGrid" AllowDrag="False"
                               FieldValueDisplayText="pivotGrid_FieldValueDisplayText" 
                               AllowFilter="False" DataProcessingEngine="Optimized"/>
        <GroupBox Grid.Row="0" Height="Auto" Margin="2,2,2,0"
                  Name="groupBox1" VerticalAlignment="Bottom">
            <StackPanel Orientation="Vertical">
                <RadioButton x:Name="rbDefault" IsChecked="True" Content="Default Layout"
                             Margin="0,0,0,2" Checked="rbDefault_Checked"/>
                <RadioButton Checked="rbDefault_Checked" Margin="0,2,0,0"
                             Content="Split Grand Total Column Header"/>
            </StackPanel>
        </GroupBox>
    </Grid>
</Window>
cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using DevExpress.XtraPivotGrid.Data;

namespace DXPivotGrid_SplittingCells {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            pivotGrid.CustomFieldValueCells += 
                new PivotCustomFieldValueCellsEventHandler(pivotGrid_CustomFieldValueCells);
        }
        void Window_Loaded(object sender, RoutedEventArgs e) {
            PivotHelper.FillPivot(pivotGrid);
            pivotGrid.DataSource = PivotHelper.GetDataTable();
            pivotGrid.BestFit();
        }
        void pivotGrid_CustomFieldValueCells(object sender, PivotCustomFieldValueCellsEventArgs e) {
            if (pivotGrid.DataSource == null) return;
            if (rbDefault.IsChecked == true) 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 == FieldValueType.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 pivotGrid_FieldValueDisplayText(object sender, PivotFieldDisplayTextEventArgs e) {
            if(e.Field == pivotGrid.Fields[PivotHelper.Month]) {
                e.DisplayText = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName((int)e.Value);
            }
        }
        private void rbDefault_Checked(object sender, RoutedEventArgs e) {
            pivotGrid.LayoutChanged();
        }
    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Imports DevExpress.XtraPivotGrid.Data

Namespace DXPivotGrid_SplittingCells

    Public Partial Class Window1
        Inherits Window

        Public Sub New()
            Me.InitializeComponent()
            AddHandler Me.pivotGrid.CustomFieldValueCells, New PivotCustomFieldValueCellsEventHandler(AddressOf pivotGrid_CustomFieldValueCells)
        End Sub

        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            PivotHelper.FillPivot(Me.pivotGrid)
            Me.pivotGrid.DataSource = GetDataTable()
            Me.pivotGrid.BestFit()
        End Sub

        Private Sub pivotGrid_CustomFieldValueCells(ByVal sender As Object, ByVal e As PivotCustomFieldValueCellsEventArgs)
            If Me.pivotGrid.DataSource Is Nothing Then Return
            If Me.rbDefault.IsChecked = True Then 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.
            Dim condition As Predicate(Of FieldValueCell) = New Predicate(Of FieldValueCell)(Function(ByVal matchCell) matchCell.ValueType = FieldValueType.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 List(Of FieldValueSplitData) = 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 pivotGrid_FieldValueDisplayText(ByVal sender As Object, ByVal e As PivotFieldDisplayTextEventArgs)
            If e.Field Is Me.pivotGrid.Fields(Month) Then
                e.DisplayText = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(CInt(e.Value))
            End If
        End Sub

        Private Sub rbDefault_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.pivotGrid.LayoutChanged()
        End Sub
    End Class
End Namespace

See Also

PivotCustomFieldValueCellsEventArgs Class

PivotCustomFieldValueCellsEventArgs Members

DevExpress.Xpf.PivotGrid Namespace