• 3 minutes to read

The Tree List control's elements can be custom painted. This can be done by using either the custom draw events designed for this purpose, or by providing your own Painter class for the control. This section contains information on creating a custom Painter class.

Tree List Painters

Tree List painters are objects implementing the ITreeListPaintHelper interface (the following section describes this interface). To create a custom painter, you need to create a class that implements the ITreeListPaintHelper interface. Alternatively, you can create a custom painter class, deriving it from the TreeList's default painter - the DevExpress.XtraTreeList.Painter.TreeListPaintHelper class

To use a custom painter, assign an instance of this class to the DefaultPainter property of the TreeList.Painter object. This property refers to an instance of the painter class that is used to paint the TreeList's elements. Initially, this property refers to a TreeListPaintHelper object.

ITreeListPaintHelper Interface

Tree List paint helpers must support the ITreeListPaintHelper interface. This interface declares methods that paint particular types of elements. The code below is the declaration of this interface.

public interface ITreeListPaintHelper { void DrawOpenCloseButton(CustomDrawNodeButtonEventArgs e); void DrawColumn(CustomDrawColumnHeaderEventArgs e); void DrawNodePreview(CustomDrawNodePreviewEventArgs e); void DrawNodeSelectImage(CustomDrawNodeImagesEventArgs e); void DrawNodeStateImage(CustomDrawNodeImagesEventArgs e); void DrawIndicator(CustomDrawNodeIndicatorEventArgs e); void DrawFooterBackGround(CustomDrawEventArgs e); void DrawRowFooterCell(CustomDrawRowFooterCellEventArgs e); void DrawFooterCell(CustomDrawFooterCellEventArgs e); void DrawNodeCell(CustomDrawNodeCellEventArgs e); }

The following table lists the methods of this interface, provides a brief description for each of them and lists the custom painting events that can be used instead.

Method Description CustomDraw Event
DrawOpenCloseButton Paints group buttons. Gets a CustomDrawNodeButtonEventArgs object as the parameter. TreeList.CustomDrawNodeButton
DrawColumn Paints elements of the column header panel. Gets a CustomDrawColumnHeaderEventArgs object as the parameter. TreeList.CustomDrawColumnHeader
DrawNodePreview Paints preview sections. Gets a CustomDrawNodePreviewEventArgs object as the parameter. TreeList.CustomDrawNodePreview
DrawNodeSelectImage Paints select images. Gets a CustomDrawNodeImagesEventArgs object as the parameter. TreeList.CustomDrawNodeImages
DrawNodeStateImage Paints state images. Gets a CustomDrawNodeImagesEventArgs object as the parameter. TreeList.CustomDrawNodeImages
DrawIndicator Paints the indicator cells. Gets a CustomDrawNodeIndicatorEventArgs object as the parameter. TreeList.CustomDrawNodeIndicator
DrawFooterBackGround Paints the summary footer's background. Gets a CustomDrawEventArgs object as the parameter. TreeList.CustomDrawFooter
DrawRowFooterCell Paints row footer cells. Gets a CustomDrawRowFooterCellEventArgs object as the parameter. TreeList.CustomDrawRowFooterCell
DrawFooterCell Paints summary footer cells. Gets a CustomDrawFooterCellEventArgs object as the parameter. TreeList.CustomDrawFooterCell
DrawNodeCell Paints the node cells. Gets a CustomDrawNodeCellEventArgs object as the parameter. TreeList.CustomDrawNodeCell


The code below creates a simple paint helper, deriving it from the standard TreeListPaintHelper class. The DrawFooterBackGround method is overridden to custom paint the summary footer.

The image below shows the Tree List control before and after the code has been executed.

CustomPaintHelper - Footer

using DevExpress.Utils;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Painter;
using System.Drawing.Drawing2D;
// ...
public class SimplePaintHelper : TreeListPaintHelper {
   internal SimplePaintHelper(ImageList il_Indicator) : base(il_Indicator) {}
   public override void DrawFooterBackGround(CustomDrawEventArgs e) {
      LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, 
Color.FromArgb(244, 210, 227), Color.FromArgb(207, 196, 230), 
      e.Graphics.FillRectangle(brush, e.Bounds);

// Use the painter:
treeList1.Painter.DefaultPaintHelper = new SimplePaintHelper(treeList1.Painter.IndicatorImages);