PivotGridControl.CustomDrawFieldValue Event
Enables column and row headers to be painted manually.
Namespace: DevExpress.XtraPivotGrid
Assembly: DevExpress.XtraPivotGrid.v18.2.dll
Declaration
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. |
Data | Gets an object that provides methods to work with data. This method supports the internal infrastructure and typically, there is no need to use it directly from your code. |
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. |
Item | For internal use. |
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 is raised before a field value, total header, grand total header or data field header is painted. The event’s parameters provide all the information required to paint the control’s headers.
If this event is raised for a field value or total header the Field parameter identifies the corresponding column field or row field. If this event is raised for a data field header the Field parameter identifies the corresponding data field. If the CustomDrawFieldValue event is raised for a grand total header the Field property will return null.
Set the Handled parameter to true to prohibit default header painting.
Important
Custom drawing of any kind is ignored when printing PivotGridControl.
Note
To access event data while an asynchronous operation is being performed, use a thread-safe event parameter returned by the PivotCustomDrawFieldValueEventArgs.ThreadSafeArgs property. To learn more, see Asynchronous Mode.
Important
Never change cell values or modify the control’s layout on this event, or any other event designed to tune the control’s appearance. Any action that causes a layout update can cause the control to malfunction.
Example
If UserLookAndFeel.Style is equal to Skin, the appearance background color settings have no effect in this instance. If you want to draw a field header using a custom color, you can draw the field header manually using the PivotGridControl.CustomDrawFieldValue
event.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-change-the-field-value-header-appearance-backcolor-or-draw-it-manually-e2809
private void pivotGridControl1_CustomDrawFieldValue(object sender,
DevExpress.XtraPivotGrid.PivotCustomDrawFieldValueEventArgs e) {
if (e.Area == DevExpress.XtraPivotGrid.PivotArea.ColumnArea) {
Rectangle rect = e.Bounds;
ControlPaint.DrawBorder3D(e.Graphics, e.Bounds);
Brush brush = e.GraphicsCache.GetSolidBrush(Color.LightYellow);
rect.Inflate(-1, -1);
e.Graphics.FillRectangle(brush, rect);
e.Appearance.DrawString(e.GraphicsCache, e.Info.Caption, e.Info.CaptionRect);
e.Painter.DrawIndicator(e.Info);
e.Handled = true;
}
else if (e.Area == DevExpress.XtraPivotGrid.PivotArea.RowArea) {
e.Painter.DrawObject(e.Info);
e.Painter.DrawIndicator(e.Info);
e.Graphics.FillRectangle(e.GraphicsCache.GetSolidBrush(Color.FromArgb(50, 0, 0, 200)), e.Bounds);
e.Handled = true;
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references 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.