TreeList.CustomDrawNodeCell Event
Provides the ability to perform custom painting of node cells.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v24.2.dll
NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList
#Declaration
[DXCategory("CustomDraw")]
public event CustomDrawNodeCellEventHandler CustomDrawNodeCell
#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 Custom |
Bounds |
Gets the painted element’s bounding rectangle.
Inherited from Custom |
Cache |
Gets an object specifying the storage for the most used pens, fonts and brushes.
Inherited from Custom |
Cell |
Gets the painted cell’s display text. |
Cell |
Gets the painted cell’s value. |
Column | Gets the painted cell’s column. |
Edit |
Gets the editor’s painter object used to paint a cell. |
Edit |
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 Custom |
Handled |
Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required.
Inherited from Custom |
Is |
Gets a value indicating whether the Tree |
Object |
Gets an object containing information about the painted element.
Inherited from Custom |
Painter |
Gets the painter object that provides the default element’s painting mechanism.
Inherited from Custom |
The event data class exposes the following methods:
Method | Description |
---|---|
Default |
Performs default painting of an element.
Inherited from Custom |
Draw |
Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements.
Inherited from Custom |
Draw |
Paints the required HTML template inside an element that raised this event.
Inherited from Custom |
#Remarks
The event parameter provides all the information necessary to paint a node cell. The e.Node
and e.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 in the following instances:
- The user activates the cell’s editor.
- When printing/exporting the Xtra
Tree TreeList. If it’s necessary to dynamically change cell styles in the print/export output of the Tree List control, handle the List. event.Node Cell Style
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 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;
}