Back to Devexpress

PivotCustomFieldValueCellsEventArgsBase.GetCellCount(Boolean) Method

corelibraries-devexpress-dot-xtrapivotgrid-dot-data-dot-pivotcustomfieldvaluecellseventargsbase-dot-getcellcount-x28-system-dot-boolean-x29.md

latest11.0 KB
Original Source

PivotCustomFieldValueCellsEventArgsBase.GetCellCount(Boolean) Method

Returns the number of field value cells in the specified area.

Namespace : DevExpress.XtraPivotGrid.Data

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

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

Declaration

csharp
public int GetCellCount(
    bool isColumn
)
vb
Public Function GetCellCount(
    isColumn As Boolean
) As Integer

Parameters

NameTypeDescription
isColumnBoolean

true to return the number of column field value cells; false to return the number of row field value cells.

|

Returns

TypeDescription
Int32

An integer value that represents the number of field value cells in the specified area.

|

Example

The following example demonstrates how handle the CustomFieldValueCells event to hide specific rows and columns. In this example, the event handler iterates through all row headers and removes rows that correspond to the “Employee B” field value, and that are not Total Rows.

View Example

cs
using System;
using System.Globalization;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;

namespace XtraPivotGrid_HidingColumnsAndRows {
    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();
        }

        // Handles the CustomFieldValueCells event to remove
        // specific rows.
        protected void pivotGrid_CustomFieldValueCells(object sender,
                             PivotCustomFieldValueCellsEventArgs e) {

            PivotGridControl pivot = sender as PivotGridControl;
            if (pivot.DataSource == null) return;
            if (radioGroup1.SelectedIndex == 0) return;

            // Iterates through all row headers.
            for (int i = e.GetCellCount(false) - 1; i >= 0; i--) {
                FieldValueCell cell = e.GetCell(false, i);
                if (cell == null) continue;

                // If the current header corresponds to the "Employee B"
                // field value, and is not the Total Row header,
                // it is removed with all corresponding rows.
                if (object.Equals(cell.Value, "Employee B") &&
                    cell.ValueType != PivotGridValueType.Total)
                    e.Remove(cell);
            }
        }
        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.Globalization
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid

Namespace XtraPivotGrid_HidingColumnsAndRows
    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

        ' Handles the CustomFieldValueCells event to remove
        ' specific rows.
        Protected Sub pivotGrid_CustomFieldValueCells(ByVal sender As Object,
                                ByVal e As PivotCustomFieldValueCellsEventArgs)

            Dim pivot As PivotGridControl = TryCast(sender, PivotGridControl)
            If pivot.DataSource Is Nothing Then
                Return
            End If
            If radioGroup1.SelectedIndex = 0 Then
                Return
            End If

            ' Iterates through all row headers.
            For i As Integer = e.GetCellCount(False) - 1 To 0 Step -1
                Dim cell As FieldValueCell = e.GetCell(False, i)
                If cell Is Nothing Then
                    Continue For
                End If

                ' If the current header corresponds to the "Employee B"
                ' field value, and is not the Total Row header,
                ' it is removed with all corresponding rows.
                If Object.Equals(cell.Value, "Employee B") AndAlso cell.ValueType <> PivotGridValueType.Total Then
                    e.Remove(cell)
                End If
            Next i
        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()
            pivotGridControl1.BestFit()
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetCellCount(Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-dashboard-pivot-custom-export/CS/WinformsExport/Form1.cs#L127

csharp
void RemoveRowByName(PivotCustomFieldValueCellsEventArgs e, params string[] rowName) {
    for(int i = e.GetCellCount(false) - 1; i >= 0; i--) {
        FieldValueCell cell = e.GetCell(false, i);

winforms-pivot-grid-hide-specific-columns-and-rows/CS/Form1.cs#L29

csharp
// Iterates through all row headers.
for (int i = e.GetCellCount(false) - 1; i >= 0; i--) {
    FieldValueCell cell = e.GetCell(false, i);

winforms-pivot-grid-hide-empty-columns-and-rows/CS/Form1.cs#L24

csharp
private void HideEmptyValues(bool isColumn, PivotCustomFieldValueCellsEventArgs e) {
    for (int i = e.GetCellCount(isColumn) - 1; i >= 0; i--) {
        FieldValueCell cell = e.GetCell(isColumn, i);

web-forms-pivot-grid-hide-particular-rows-and-columns/CS/ASPxPivotGrid_HidingColumnsAndRows/Default.aspx.cs#L25

csharp
// Iterates through all row headers.
for (int i = e.GetCellCount(false) - 1; i >= 0; i--) {
    FieldValueCell cell = e.GetCell(false, i);

winforms-dashboard-pivot-custom-export/VB/WinFormsExport/Form1.vb#L132

vb
Private Sub RemoveRowByName(ByVal e As PivotCustomFieldValueCellsEventArgs, ParamArray ByVal rowName() As String)
    For i As Integer = e.GetCellCount(False) - 1 To 0 Step -1
        Dim cell As FieldValueCell = e.GetCell(False, i)

winforms-pivot-grid-hide-specific-columns-and-rows/VB/Form1.vb#L34

vb
' Iterates through all row headers.
For i As Integer = e.GetCellCount(False) - 1 To 0 Step -1
    Dim cell As FieldValueCell = e.GetCell(False, i)

winforms-pivot-grid-hide-empty-columns-and-rows/VB/Form1.vb#L29

vb
Private Sub HideEmptyValues(ByVal isColumn As Boolean, ByVal e As PivotCustomFieldValueCellsEventArgs)
    For i As Integer = e.GetCellCount(isColumn) - 1 To 0 Step -1
        Dim cell As FieldValueCell = e.GetCell(isColumn, i)

web-forms-pivot-grid-hide-particular-rows-and-columns/VB/ASPxPivotGrid_HidingColumnsAndRows/Default.aspx.vb#L26

vb
' Iterates through all row headers.
For i As Integer = e.GetCellCount(False) - 1 To 0 Step -1
    Dim cell As FieldValueCell = e.GetCell(False, i)

See Also

PivotCustomFieldValueCellsEventArgsBase Class

PivotCustomFieldValueCellsEventArgsBase Members

DevExpress.XtraPivotGrid.Data Namespace