PivotGridControl.CustomDrawFieldValue Event

Enables column and row headers to be painted manually.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v21.1.dll

Declaration

public event PivotCustomDrawFieldValueEventHandler CustomDrawFieldValue

Event Data

The CustomDrawFieldValue event's data class is PivotCustomDrawFieldValueEventArgs. The following properties provide information specific to this event:

Property Description
Appearance Gets the painted element’s appearance settings. Inherited from PivotCustomDrawEventArgs.
Area Gets the header area where the field is displayed.
Bounds Gets the bounding rectangle of the painted element. Inherited from PivotCustomDrawEventArgs.
CustomTotal Gets the custom total which the currently processed column/row header corresponds to.
DisplayText Gets the display text of the header currently being painted.
Field Gets the field whose value is to be painted.
FieldIndex Gets the field’s position among the visible fields within the header area.
Graphics Gets an object used to paint an element. Inherited from PivotCustomDrawEventArgs.
GraphicsCache Gets an object which specifies the storage for the most used pens, fonts and brushes. Inherited from PivotCustomDrawEventArgs.
Handled Gets or sets whether an event was handled, if it was handled the default actions are not required. Inherited from PivotCustomDrawEventArgs.
Info Gets an object which provides the information required to paint a field value.
IsOthersValue Gets whether the current header corresponds to the “Others” row/column.
MaxIndex Gets the maximum row index (for row fields) or column index (for column fields) that corresponds to the field value currently being processed.
MinIndex Gets the minimum row index (for row fields) or column index (for column fields) that corresponds to the field value currently being processed.
Painter Gets the painter object that provides the default element painting mechanism.
ThreadSafeArgs Gets an event parameter that provides thread-safe access to event data.
Value Gets the value of the column field or row field which the currently processed column/row header corresponds to.
ValueType Gets the type of the currently processed column/row header.

The event data class exposes the following methods:

Method Description
DefaultDraw() Performs default painting of an element. Inherited from PivotCustomDrawEventArgs.
GetCellValue(Int32, Int32) Returns a value displayed in the specified cell.
GetFieldValue(PivotGridField, Int32) Returns the specified column or row field’s value for the cell addressed by its zero-based index in the Data Area.
GetHigherLevelFields() Returns the parent field(s) for the field value being currently processed.
GetHigherLevelFieldValue(PivotGridField) Returns the value of a specific parent field corresponding to the field value currently being processed.

Remarks

The CustomDrawFieldValue event occurs before painting the field value, total header, grand total header or data field header. The event’s parameters provide the information required to paint the control’s headers.

The following table helps you identify the painted visual element:

Element e.Field value
field value identifies the column field or row field
data field header the data field
grand total header null

Set the e.Handled property to true to skip default header painting.

IMPORTANT

The Pivot Grid control ignores custom draw in export procedures.

To access event data in an asynchronous operation, use a thread-safe event parameter returned by the PivotCustomDrawFieldValueEventArgs.ThreadSafeArgs property. For more information, refer to the Asynchronous Mode article.

IMPORTANT

Do not change cell values, modify the control’s layout, or change the control’s object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

Example

If UserLookAndFeel.Style is set to Skin, the appearance background color settings have no effect. To set a custom background color, draw the field header manually in the PivotGridControl.CustomDrawFieldValue event handler.

pivot-customdrawfieldvalue

NOTE

The complete sample project How to Change the Field Value Header Background with the CustomDrawFieldValue Event is available in the DevExpress Examples repository.

private void pivotGridControl1_CustomDrawFieldValue(object sender, 
    DevExpress.XtraPivotGrid.PivotCustomDrawFieldValueEventArgs e) {
    if (e.Area == DevExpress.XtraPivotGrid.PivotArea.ColumnArea) {
        e.Appearance.BackColor = Color.GreenYellow;
    }
    else if (e.Area == DevExpress.XtraPivotGrid.PivotArea.RowArea) {
        e.Painter.DrawObject(e.Info);
        e.Painter.DrawIndicator(e.Info);
        e.GraphicsCache.FillRectangle(e.GraphicsCache.GetSolidBrush(Color.FromArgb(50, 0, 0, 200)), e.Bounds);
        e.Handled = true;
    }
}
See Also