Back to Devexpress

PivotGridControl.CustomDrawFieldValue Event

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-29cce2cc.md

latest12.9 KB
Original Source

PivotGridControl.CustomDrawFieldValue Event

Enables column and row headers to be painted manually.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public event PivotCustomDrawFieldValueEventHandler CustomDrawFieldValue
vb
Public Event CustomDrawFieldValue As PivotCustomDrawFieldValueEventHandler

Event Data

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

PropertyDescription
AppearanceGets the painted element’s appearance settings. Inherited from PivotCustomDrawEventArgs.
AreaGets the header area where the field is displayed.
BoundsGets the bounding rectangle of the painted element. Inherited from PivotCustomDrawEventArgs.
CustomTotalGets the custom total which the currently processed column/row header corresponds to.
DisplayTextGets the display text of the header currently being painted.
FieldGets the field whose value is to be painted.
FieldIndexGets the field’s position among the visible fields within the header area.
GraphicsGets an object used to paint an element. Inherited from PivotCustomDrawEventArgs.
GraphicsCacheGets an object which specifies the storage for the most used pens, fonts and brushes. Inherited from PivotCustomDrawEventArgs.
HandledGets or sets whether an event was handled, if it was handled the default actions are not required. Inherited from PivotCustomDrawEventArgs.
InfoGets an object which provides the information required to paint a field value.
IsOthersValueGets whether the current header corresponds to the “Others” row/column.
MaxIndexGets the maximum row index (for row fields) or column index (for column fields) that corresponds to the field value currently being processed.
MinIndexGets the minimum row index (for row fields) or column index (for column fields) that corresponds to the field value currently being processed.
PainterGets the painter object that provides the default element painting mechanism.
ThreadSafeArgsGets an event parameter that provides thread-safe access to event data.
ValueGets the value of the column field or row field which the currently processed column/row header corresponds to.
ValueTypeGets the type of the currently processed column/row header.

The event data class exposes the following methods:

MethodDescription
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:

Elemente.Field value
field valueidentifies the column field or row field
data field headerthe data field
grand total headernull

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

The following code snippet draws the field header manually in the PivotGridControl.CustomDrawFieldValue event handler.

View Example

cs
private void pivotGridControl1_CustomDrawFieldValue(object sender, PivotCustomDrawFieldValueEventArgs e) {
    if (e.Area == PivotArea.ColumnArea) {
        e.Appearance.BackColor = Color.GreenYellow;
    }
    else if (e.Area == 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;
    }
}
vb
Private Sub pivotGridControl1_CustomDrawFieldValue(ByVal sender As Object, ByVal e As PivotCustomDrawFieldValueEventArgs) Handles pivotGridControl1.CustomDrawFieldValue
    If e.Area = PivotArea.ColumnArea Then
        e.Appearance.BackColor = Color.GreenYellow
    ElseIf e.Area = PivotArea.RowArea Then
        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
    End If
End Sub

More Examples

View Example: Draw a Custom Element When a User Hovers Over a Field Value

View Example: Hide Unnecessary Grid Lines and Text

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawFieldValue event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-pivot-grid-hide-the-grand-total-column-and-text-labels/CS/RemoveGridLinesExample/Form1.cs#L17

csharp
InitializeFields();
pivotGridControl1.CustomDrawFieldValue += pivotGridControl1_CustomDrawFieldValue;
pivotGridControl1.Appearance.Lines.BackColor = Color.Transparent;

winforms-pivot-grid-hide-the-grand-total-column-and-text-labels/VB/RemoveGridLinesExample/Form1.vb#L20

vb
InitializeFields()
AddHandler pivotGridControl1.CustomDrawFieldValue, AddressOf pivotGridControl1_CustomDrawFieldValue
pivotGridControl1.Appearance.Lines.BackColor = Color.Transparent

See Also

CustomDrawCell

CustomDrawEmptyArea

CustomDrawFieldHeader

CustomDrawFieldHeaderArea

FieldValueDisplayText

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace