Skip to main content

PivotCustomFieldValueCellsEventArgs.FindCell(Boolean, Predicate<Object[]>) Method

Returns header of the column/row whose summary values match the specified condition.

Namespace: DevExpress.Xpf.PivotGrid

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

NuGet Package: DevExpress.Wpf.PivotGrid

Declaration

public FieldValueCell FindCell(
    bool isColumn,
    Predicate<object[]> match
)

Parameters

Name Type Description
isColumn Boolean

true to locate a column; false to locate a row.

match Predicate<Object[]>

A System.Predicate that specifies the condition used to locate the column/row.

Returns

Type Description
FieldValueCell

A FieldValueCell object representing the header of the column/row whose summary values match the specified predicate; null if no columns/rows match the predicate.

Remarks

Field value cells can also be obtained by their indexes using the PivotCustomFieldValueCellsEventArgs.GetCell method.

Example

The following example demonstrates how to handle the CustomFieldValueCells event to locate a specific column/row header identified by its column’s/row’s summary values.

In this example, a predicate is used to locate a column that contains only zero summary values. The column header is obtained by the event parameter’s FindCell method, and then removed via the Remove method.

Imports Microsoft.VisualBasic
Imports System
Imports System.Globalization
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid

Namespace DXPivotGrid_FindCells
    Partial Public Class Window1
        Inherits Window
        Public Sub New()
            InitializeComponent()
            AddHandler pivotGrid.CustomFieldValueCells, AddressOf pivotGrid_CustomFieldValueCells
        End Sub
        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            PivotHelper.FillPivot(pivotGrid)
            pivotGrid.DataSource = PivotHelper.GetDataTable()
            pivotGrid.BestFit()
        End Sub

        ' Handles the CustomFieldValueCells event to remove columns with
        ' zero summary values.
        Private Sub pivotGrid_CustomFieldValueCells(ByVal sender As Object, _
                                                    ByVal e As PivotCustomFieldValueCellsEventArgs)
            If pivotGrid.DataSource Is Nothing Then
                Return
            End If
            If rbDefault.IsChecked = True Then
                Return
            End If

            ' Obtains the first encountered column header whose column
            ' matches the specified condition, represented by a predicate.
            Dim cell As FieldValueCell = _
                e.FindCell(True, New Predicate(Of Object())( _
                           Function(dataCellValues) AnonymousMethod1(dataCellValues)))

            ' If any column header matches the condition, this column is removed.
            If cell IsNot Nothing Then
                e.Remove(cell)
            End If
        End Sub

        ' Defines the predicate returning true for columns
        ' that contain only zero summary values.
        Private Function AnonymousMethod1(ByVal dataCellValues() As Object) As Boolean
            For Each value As Object In dataCellValues
                If (Not Object.Equals(CDec(0), value)) Then
                    Return False
                End If
            Next value
            Return True
        End Function
        Private Sub pivotGrid_FieldValueDisplayText(ByVal sender As Object, _
                                                    ByVal e As PivotFieldDisplayTextEventArgs)
            If Object.Equals(e.Field, pivotGrid.Fields(PivotHelper.Month)) Then
                e.DisplayText = _
                    CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(CInt(Fix(e.Value)))
            End If
        End Sub
        Private Sub rbDefault_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
            pivotGrid.LayoutChanged()
        End Sub
    End Class
End Namespace
See Also