# TreeList.CustomDrawNodeCell Event | WinForms Controls | DevExpress Documentation

# TreeList.CustomDrawNodeCell Event

Provides the ability to perform custom painting of node [cells](/WindowsForms/1072/controls-and-libraries/tree-list/visual-elements/cell).

**Namespace**: [DevExpress.XtraTreeList](/WindowsForms/DevExpress.XtraTreeList)

        **Assembly**:
        DevExpress.XtraTreeList.v26.1.dll

## Declaration

- C#
- VB.NET

                        <section id="tabpanel_syntax_tabid_DevExpress.XtraTreeList.TreeList.CustomDrawNodeCell-csharp" role="tabpanel" data-tab="tabid-csharp" class="tab-group__tab-content tab-group__tab-content--code" style="display: block">
                            <pre><code data-code-links="{&quot;CustomDrawNodeCellEventHandler&quot;:&quot;/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventHandler&quot;,&quot;CustomDrawNodeCellEventArgs&quot;:&quot;/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs&quot;}" class="lang-csharp hljs">[DXCategory(&quot;CustomDraw&quot;)]&#xA;public event CustomDrawNodeCellEventHandler CustomDrawNodeCell</code></pre>
                        </section>
                        <section id="tabpanel_syntax_tabid_DevExpress.XtraTreeList.TreeList.CustomDrawNodeCell-vb" role="tabpanel" data-tab="tabid-vb" class="tab-group__tab-content tab-group__tab-content--code" style="display: none">
                            <pre><code data-code-links="{&quot;CustomDrawNodeCellEventHandler&quot;:&quot;/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventHandler&quot;,&quot;CustomDrawNodeCellEventArgs&quot;:&quot;/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs&quot;}" class="lang-vb hljs">&lt;DXCategory(&quot;CustomDraw&quot;)&gt;&#xA;Public Event CustomDrawNodeCell As CustomDrawNodeCellEventHandler</code></pre>
                        </section>

## Event Data

The **CustomDrawNodeCell** event's data class is [CustomDrawNodeCellEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs).
                    The following properties provide information specific to this event:

| Property | Description |
| --- | --- |
| [Appearance](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.Appearance) | Gets the painted element’s appearance settings.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [Bounds](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.Bounds) | Gets the painted element’s bounding rectangle.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [Cache](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.Cache) | Gets an object specifying the storage for the most  used pens, fonts and brushes.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [CellText](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.CellText) | Gets the painted cell’s display text. |
| [CellValue](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.CellValue) | Gets the painted cell’s value. |
| [Column](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.Column) | Gets the painted cell’s column. |
| [EditPainter](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.EditPainter) | Gets the editor’s painter object used to paint a cell. |
| [EditViewInfo](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.EditViewInfo) | Gets the editor’s view information. |
| [Focused](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.Focused) | Gets a value indicating whether the painted cell has focus. |
| [Graphics](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.Graphics) | Gets an object used to paint.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [Handled](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.Handled) | Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [IsRightToLeft](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.IsRightToLeft) | Gets a value indicating whether the TreeList’s elements are aligned to support locales using right-to-left fonts.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [ObjectArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.ObjectArgs) | Gets an object containing information about the painted element.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [Painter](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.Painter) | Gets the painter object that provides the default element’s painting mechanism.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |

The event data class exposes the following methods:

| Method | Description |
| --- | --- |
| [DefaultDraw()](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.DefaultDraw) | Performs default painting of an element.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action&lt;DxHtmlPainterArgs&gt;)](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.DrawHtml%28HtmlTemplate--DxHtmlPainterContext--Action-DxHtmlPainterArgs-%29) | Paints the required [HTML template](/WindowsForms/403397/common-features/html-css-based-desktop-ui) inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |
| [DrawHtml(HtmlTemplate, Action&lt;DxHtmlPainterArgs&gt;)](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs.DrawHtml%28DevExpress.Utils.Html.HtmlTemplate-System.Action-DevExpress.Utils.Html.DxHtmlPainterArgs-%29) | Paints the required [HTML template](/WindowsForms/403397/common-features/html-css-based-desktop-ui) inside an element that raised this event.<br>Inherited from [CustomDrawEventArgs](/WindowsForms/DevExpress.XtraTreeList.CustomDrawEventArgs). |

## Remarks

The event parameter provides all the information necessary to paint a node [cell](/WindowsForms/1072/controls-and-libraries/tree-list/visual-elements/cell). The `e.Node` and [e.Column](/WindowsForms/DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs.Column) parameter properties allow you to identify the node and column to which a cell belongs.

See the [Custom Draw Scenarios](/WindowsForms/5660/controls-and-libraries/tree-list/feature-center/appearances-and-look-and-feel/custom-drawing/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 XtraTreeList. If it’s necessary to dynamically change cell styles in the print/export output of the Tree List control, handle the [TreeList.NodeCellStyle](/WindowsForms/DevExpress.XtraTreeList.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.

## 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.

![CustomDraw - NodeCell](/WindowsForms/images/customdraw-nodecell1021.png)

- C#
- VB.NET

<section id="tabpanel_Xnlzt9WKZ+_tabid-csharp" role="tabpanel" data-tab="tabid-csharp">
<pre><code data-code-links="{&quot;/ (System.Drawing)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.drawing&quot;,&quot;/ (System.Drawing.Drawing2D)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.drawing.drawing2d&quot;,&quot;/ (DevExpress.XtraTreeList)(?:;|$)/&quot;:&quot;/WindowsForms/DevExpress.XtraTreeList&quot;}" class="lang-csharp">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;
}
</code></pre></section>
<section id="tabpanel_Xnlzt9WKZ+_tabid-vb" role="tabpanel" data-tab="tabid-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (System.Drawing)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.drawing&quot;,&quot;/ (System.Drawing.Drawing2D)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.drawing.drawing2d&quot;,&quot;/ (DevExpress.XtraTreeList)(?:;|$)/&quot;:&quot;/WindowsForms/DevExpress.XtraTreeList&quot;}" class="lang-vb">Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports DevExpress.XtraTreeList

Private Sub TreeList1_CustomDrawNodeCell(sender As Object, e As DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs) Handles TreeList1.CustomDrawNodeCell
    &#39; Create brushes for cells.
    Dim BackBrush, ForeBrush As Brush
    If e.Node.Id &lt;&gt; sender.FocusedNode.Id Then
        BackBrush = e.Cache.GetGradientBrush(e.Bounds, Color.PapayaWhip,
                                             Color.PeachPuff, LinearGradientMode.ForwardDiagonal)
        ForeBrush = Brushes.Black
    Else
        BackBrush = Brushes.DarkBlue
        ForeBrush = Brushes.PeachPuff
    End If
    &#39; Fill the background.
    e.Cache.FillRectangle(BackBrush, e.Bounds)
    &#39; Paint the node value.
    e.Cache.DrawString(e.CellText, e.Appearance.Font, ForeBrush, e.Bounds,
                       e.Appearance.GetStringFormat())

    &#39; Prohibit default painting
    e.Handled = True
End Sub
</code></pre></section>

See Also

[CustomDrawFooter](/WindowsForms/DevExpress.XtraTreeList.TreeList.CustomDrawFooter)

[CustomDrawFooterCell](/WindowsForms/DevExpress.XtraTreeList.TreeList.CustomDrawFooterCell)

[CustomDrawRowFooter](/WindowsForms/DevExpress.XtraTreeList.TreeList.CustomDrawRowFooter)

[CustomDrawRowFooterCell](/WindowsForms/DevExpress.XtraTreeList.TreeList.CustomDrawRowFooterCell)

[CustomDrawNodeIndicator](/WindowsForms/DevExpress.XtraTreeList.TreeList.CustomDrawNodeIndicator)

[NodeCellStyle](/WindowsForms/DevExpress.XtraTreeList.TreeList.NodeCellStyle)

[TreeList Class](/WindowsForms/DevExpress.XtraTreeList.TreeList)

[TreeList Members](/WindowsForms/DevExpress.XtraTreeList.TreeList._members)

[DevExpress.XtraTreeList Namespace](/WindowsForms/DevExpress.XtraTreeList)