Skip to main content

PivotCustomFieldValueCellsEventArgsBase.Remove(FieldValueCellBase) Method

Removes the specified field value cell.

Namespace: DevExpress.XtraPivotGrid.Data

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

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

Declaration

public bool Remove(
    FieldValueCellBase cell
)

Parameters

Name Type Description
cell FieldValueCellBase

A FieldValueCellBase descendant that represents the field value cell to remove.

Returns

Type Description
Boolean

true if the specified cell has been found and removed; false if the specified cell has not been found.

Remarks

To locate the required field value cell, use the GetCell or FindCell method implemented in the PivotCustomFieldValueCellsEventArgsBase class descendants.

Note that if a field value cell has only one child cell, and this child cell is removed via the Remove method, the parent cell is then automatically removed.

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

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the Remove(FieldValueCellBase) 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.

See Also