TreeList.CustomDrawNodeCell Event

Provides the ability to perform custom painting of node cells.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v20.1.dll

Declaration

[DXCategory("CustomDraw")]
public event CustomDrawNodeCellEventHandler CustomDrawNodeCell
<DXCategory("CustomDraw")>
Public Event CustomDrawNodeCell As CustomDrawNodeCellEventHandler

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.

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

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.

Examples

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.

CustomDraw - NodeCell

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;
}
See Also