Skip to main content

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

Returns an array of the row fields that correspond to the current cell.

Namespace: DevExpress.XtraPivotGrid

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

Declaration

public TField[] GetRowFields()

Returns

Type Description
TField[]

An array of row fields.

Remarks

The Pivot Grid supports multiple row fields. Use the GetRowFields method to get the row fields that correspond to the current cell. If the cell belongs to a Row Grand Total, the GetRowFields method returns an empty array (the array’s length is 0).

Use the e.RowField property to get the innermost row field that corresponds to the current cell. This property’s value matches the value of the last element in the array returned by the GetRowFields method.

Use the e.GetFieldValue method to get any field’s value for the current cell.

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