Skip to main content

PivotCellEventArgsBase<TField, TData, TCustomTotal>.GetFieldValue(TField, Int32) Method

Returns the specified column or row field’s value for the cell, addressed by its zero-based index in the data area.

Namespace: DevExpress.XtraPivotGrid

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

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

Declaration

public object GetFieldValue(
    TField field,
    int cellIndex
)

Parameters

Name Type Description
field TField

A column or row field, whose value is to be obtained.

cellIndex Int32

A zero-based index of a cell in the data area that identifies the field value. Indexes starts from the left edge for column fields, and from the top edge for row fields.

Returns

Type Description
Object

The field value.

Remarks

To get a row field’s value for the current row, pass the e.RowIndex property’s value as the cellIndex parameter. To get a column field’s value, use the e.ColumnIndex property.

The following image shows cell indexes that numerate rows and columns:

GetFieldValue

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