Skip to main content

PivotCellEventArgsBase<TField, TData, TCustomTotal>.GetCellValue(TField) Method

Returns a cell value calculated against the specified data field.

Namespace: DevExpress.XtraPivotGrid

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

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

Declaration

public object GetCellValue(
    TField dataField
)

Parameters

Name Type Description
dataField TField

A T object that specifies the data field.

Returns

Type Description
Object

A summary value calculated against the specified data field.

Remarks

Call the GetCellValue method when the Pivot Grid contains two or more data fields. In this case, columns (rows) contain sub-columns (sub-rows) that correspond to the data fields. The GetCellValue method allows you to obtain a cell value calculated for the same column and row field values as the processed cell value, but against the specified data field. The dataField parameter identifies the sub-column (sub-row) in which the desired cell resides.

The value of the processed cell can be obtained via the e.Value property.

Note

Note that the GetCellValue method returns values calculated based on the data source data and ignores custom cell values suppled with the CustomCellValue event. Use the e.Value property to obtain a custom cell value.

Example

This example calculates percentage based on the Beverages row value for each column. The Pivot Grid handles the PivotGridControl.CustomCellValue event to display a calculated percentage value in the cell that belongs to the % of Beverages Sales column. The grand total values are hidden.

Percent of beverages Sales

View Example

private void pivotGridControl1_CustomCellValue(object sender, PivotCellValueEventArgs e) {
    // Calculates the 'Percent' field values.
    if (e.DataField.Name == "PercentOfBeverages") {
        // Hides grand total values.
        if (e.RowValueType == PivotGridValueType.GrandTotal) {
            e.Value = null;
            return;
        }
        var rowValues = e.GetRowFields().Select(f => 
            f == fieldCategoryName ? "Beverages" : e.GetFieldValue(f)).ToArray();
        var columnValues = e.GetColumnFields().Select(f => 
            f == fieldCategoryName ? "Beverages" : e.GetFieldValue(f)).ToArray();
        decimal beveragesValue = Convert.ToDecimal(e.GetCellValue(columnValues, rowValues, e.DataField));
        if (beveragesValue == 0)
            e.Value = null;
        else
            e.Value = Convert.ToDecimal(e.Value) / beveragesValue;
    }
    else return;
}
See Also