ASPxPivotGrid.CustomCellStyle Event

Allows the appearances of cells to be dynamically customized.

Namespace: DevExpress.Web.ASPxPivotGrid

Assembly: DevExpress.Web.ASPxPivotGrid.v19.2.dll

Declaration

public event PivotCustomCellStyleEventHandler CustomCellStyle
Public Event CustomCellStyle As PivotCustomCellStyleEventHandler

Event Data

The CustomCellStyle event handler receives an argument of the PivotCustomCellStyleEventArgs type. The following properties provide information specific to this event.

Property Description
CellItem For internal use.
(Inherited from PivotCellBaseEventArgs)
CellStyle Gets the style settings used to paint the processed cell.
ColumnCustomTotal Gets the column custom total which displays the current cell.
ColumnField Gets the innermost column field which corresponds to the processed cell.
ColumnFieldIndex For internal use.
ColumnIndex Gets the visual index of the column that contains the processed cell.
ColumnValueType Gets the type of column which contains the processed cell.
Data For internal use.
DataField Gets the data field which identifies the column where the processed cell resides.
Item For internal use.
RowCustomTotal Gets the row custom total which contains the current cell.
RowField Gets the innermost row field which corresponds to the processed cell.
RowFieldIndex For internal use.
RowIndex Gets the index of the row that contains the processed cell.
RowValueType Gets the type of row which contains the processed cell.
SummaryType Gets the summary type of the currently processed value.
SummaryValue Gets the summary value currently being processed.
Value Gets the processed cell's value.

Remarks

The CustomCellStyle event fires for each ASPxPivotGridControl's cell and allows you to customize the appearance of cells dynamically (depending on their contents, position, values of other cells, etc). Use the event's parameters to identify the processed cell.

PivotGrid allows obtaining a field's value both for hidden and visible fields. ASPxPivotGrid does not aggregate data by hidden fields. You need to get a value from the underlying data source records corresponding to a processed cell. Use the PivotCellEventArgsBase<TField, TData, TCustomTotal>.CreateDrillDownDataSource method to obtain hidden field's values. To get a visible field's value, use the PivotCellEventArgsBase<TField, TData, TCustomTotal>.GetCellValue method.

Examples

In this example, the ASPxPivotGrid.CustomCellStyle event is handled to specify custom style settings of individual summary cells displayed within odd rows. The PivotFieldValueStyle.TopAlignedRowValues property aligns field values to the top edge of their cells.

using System;
using DevExpress.XtraPivotGrid;
using System.Drawing;

namespace CellAppearanceCustomization {
    public partial class DefaultForm : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

        }
        protected void ASPxPivotGrid1_CustomCellStyle(object sender, DevExpress.Web.ASPxPivotGrid.PivotCustomCellStyleEventArgs e) {
            if(!cbApplyCustomCellAppearance.Checked) return;
            if(e.RowIndex % 2 == 0) return;
            if(e.ColumnValueType == PivotGridValueType.Value && e.RowValueType == PivotGridValueType.Value)
                e.CellStyle.BackColor = Color.FromArgb(240, 240, 240);
            if(e.ColumnValueType == PivotGridValueType.Total || e.RowValueType == PivotGridValueType.Total)
                e.CellStyle.BackColor = Color.FromArgb(213, 227, 230);
            if(e.ColumnValueType == PivotGridValueType.GrandTotal || e.RowValueType == PivotGridValueType.GrandTotal)
                e.CellStyle.BackColor = Color.FromArgb(187, 211, 215);
        }
        protected void cbTopAlignRowFieldValues_CheckedChanged(object sender, EventArgs e) {
            pivotGrid.Styles.FieldValueStyle.TopAlignedRowValues = cbTopAlignRowFieldValues.Checked;
        }
    }
}
See Also