PivotCustomFieldValueCellsEventArgs.FindCell(Boolean, Predicate<Object[]>) Method
Returns the header of the column/row whose summary values match the specified condition.
Namespace: DevExpress.Web.ASPxPivotGrid
Assembly: DevExpress.Web.ASPxPivotGrid.v19.2.dll
Declaration
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-locate-field-value-cells-matching-a-particular-condition-e2770
using System;
using System.Globalization;
using System.Web.UI;
using DevExpress.Web.ASPxPivotGrid;
using DevExpress.XtraPivotGrid;
namespace ASPxPivotGrid_FindCells {
public partial class _Default : Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsCallback && !IsPostBack) {
PivotHelper.FillPivot(pivotGrid);
}
pivotGrid.DataSource = PivotHelper.GetDataTable();
}
// Handles the CustomFieldValueCells event to remove columns with
// zero summary values.
protected void pivotGrid_CustomFieldValueCells(object sender,
PivotCustomFieldValueCellsEventArgs e) {
if (pivotGrid.DataSource == null) return;
if (radioButtonList.SelectedIndex == 0) return;
// Obtains the first encountered column header whose column
// matches the specified condition, represented by a predicate.
FieldValueCell cell = e.FindCell(true, new Predicate<object[]>(
// Defines the predicate returning true for columns
// that contain only zero summary values.
delegate(object[] dataCellValues) {
foreach (object value in dataCellValues) {
if (!object.Equals((decimal)0, value))
return false;
}
return true;
}));
// If any column header matches the condition, this column is removed.
if (cell != null) e.Remove(cell);
}
protected void pivotGrid_FieldValueDisplayText(object sender,
PivotFieldDisplayTextEventArgs e) {
if (e.Field == pivotGrid.Fields[PivotHelper.Month]) {
e.DisplayText = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName((int)e.Value);
}
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindCell(Boolean, Predicate<Object[]>) 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.