PivotCellEventArgsBase<TField, TData, TCustomTotal>.GetCellValue(Object[], Object[], TField) Method
Returns a cell value calculated for the specified column and row field values, against the specified data field.
Namespace: DevExpress.XtraPivotGrid
Assembly: DevExpress.PivotGrid.v23.1.Core.dll
NuGet Packages: DevExpress.PivotGrid.Core, DevExpress.Win.Dashboard.Design
Declaration
Parameters
Name | Type | Description |
---|---|---|
columnValues | Object[] | An array of column values. |
rowValues | Object[] | An array of row values. |
dataField | TField | A T object that specifies the data field, against which the required cell value is calculated. |
Returns
Type | Description |
---|---|
Object | A summary value calculated for the specified column and row field values, against the specified data field. |
Remarks
The following table illustrates how to use the GetCellValue
method to obtain specific cell values:
Cell | C# | Visual Basic |
---|---|---|
Blue | e.GetCellValue(new object[] {1995, 1}, new object[] {"Alice Mutton"}, fieldProductAmount); |
e.GetCellValue(New Object() {1995, 1}, New Object() {"Alice Mutton"}, fieldProductAmount) |
Red | e.GetCellValue(new object[] {1995}, new object[] {"Chai"}, fieldProductAmount); |
e.GetCellValue(New Object() {1995}, New Object() {"Chai"}, fieldProductAmount) |
Green | e.GetCellValue(null, new object[] {"Chang"}, fieldProductAmount); |
e.GetCellValue(Nothing, New Object() {"Chang"}, fieldProductAmount) |
The image below illustrates values that GetCellValue
obtains.
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.
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;
}