TreeList.CustomDrawNodeCell Event
Provides the ability to perform custom painting of node cells.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v19.2.dll
Declaration
Event Data
The CustomDrawNodeCell event's data class is CustomDrawNodeCellEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Appearance | Gets the painted element’s appearance settings. Inherited from CustomDrawEventArgs. |
Bounds | Gets the painted element’s bounding rectangle. Inherited from CustomDrawEventArgs. |
Cache | Gets an object specifying the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs. |
CellText | Gets the painted cell’s display text. |
CellValue | Gets the painted cell’s value. |
Column | Gets the painted cell’s column. |
EditPainter | Gets the editor’s painter object used to paint a cell. |
EditViewInfo | Gets the editor’s view information. |
Focused | Gets a value indicating whether the painted cell has focus. |
Graphics | Gets an object used to paint. Inherited from CustomDrawEventArgs. |
Handled | Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs. |
IsRightToLeft | Gets a value indicating whether the TreeList’s elements are aligned to support locales using right-to-left fonts. Inherited from CustomDrawEventArgs. |
ObjectArgs | Gets an object containing information about the painted element. Inherited from CustomDrawEventArgs. |
Painter | Gets the painter object that provides the default element’s painting mechanism. Inherited from CustomDrawEventArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
DefaultDraw() | Performs default painting of an element. Inherited from CustomDrawEventArgs. |
Remarks
The event parameter provides all the information necessary to paint a node cell. The Node and CustomDrawNodeCellEventArgs.Column parameter properties allow you to identify the node and column to which a cell belongs.
See the Custom Draw Scenarios topic for information on using custom draw events.
Note
Custom drawing of any kind is ignored when printing/exporting the XtraTreeList. If it’s necessary to dynamically change cell styles in the print/export output of the Tree List control, handle the TreeList.NodeCellStyle event.
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
The following sample code handles the TreeList.CustomDrawNodeCell
event. It is used to perform custom painting of node cells. All node cells are painted in the same manner.
The image below illustrates the result of executing the sample code.
using System.Drawing;
using System.Drawing.Drawing2D;
using DevExpress.XtraTreeList;
private void treeList1_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e) {
// Create brushes for cells.
Brush backBrush, foreBrush;
if (e.Node != (sender as TreeList).FocusedNode)
{
backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.PapayaWhip, Color.PeachPuff, LinearGradientMode.ForwardDiagonal);
foreBrush = Brushes.Black;
}
else
{
backBrush = Brushes.DarkBlue;
foreBrush = e.Cache.GetSolidBrush(Color.PeachPuff);
}
// Fill the background.
e.Cache.FillRectangle(backBrush, e.Bounds);
// Paint the node value.
e.Cache.DrawString(e.CellText, e.Appearance.Font, foreBrush, e.Bounds,
e.Appearance.GetStringFormat());
// Prohibit default painting.
e.Handled = true;
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomDrawNodeCell 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.