Skip to main content
A newer version of this page is available. .

VGridControlBase.CustomDrawTreeButton Event

Enables expand buttons to be painted manually.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v18.2.dll

Declaration

public event CustomDrawTreeButtonEventHandler CustomDrawTreeButton

Event Data

The CustomDrawTreeButton event's data class is CustomDrawTreeButtonEventArgs. The following properties provide information specific to this event:

Property Description
Appearance Gets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
Bounds Gets a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
Cache Gets an object which specifies the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs.
Expanded Gets a value indicating whether the painted button’s corresponding row is expanded.
Graphics Gets an object used to paint. Inherited from CustomDrawEventArgs.
Handled Gets or sets a value specifying whether an event was handled, if handled, default actions are not required. Inherited from CustomDrawEventArgs.
IsRightToLeft Gets a value indicating whether the VGridControl‘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.
Properties Provides properties specific to the row being custom painted. Inherited from CustomDrawRowEventArgs.
Row Gets the row whose element is to be drawn. Inherited from CustomDrawRowEventArgs.
TreeButtonType Gets the painted button’s type.

The event data class exposes the following methods:

Method Description
DefaultDraw() Performs default painting of an element. Inherited from CustomDrawEventArgs.

Remarks

The CustomDrawTreeButton event is raised before an expand button is painted. The button’s row is identified by the CustomDrawRowEventArgs.Row parameter. The CustomDrawTreeButtonEventArgs.Expanded property allows you to determine whether the processed expand button corresponds to the expanded or collapsed state of a row. The button’s type is identified by the CustomDrawTreeButtonEventArgs.TreeButtonType property.

The CustomDrawTreeButton event can be used for two purposes:

  • To manually paint all or only particular expand buttons. Note that you need to set the CustomDrawEventArgs.Handled parameter to true to indicate that the default painting is not required for the button.
  • Change the button’s appearance settings and leave the CustomDrawEventArgs.Handled parameter set to false. This will paint buttons using the default mechanism but with modified settings.

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 shows how to use the VGridControlBase.CustomDrawTreeButton event to paint tree buttons. Custom painting is not applied to category expand buttons, these buttons are painted in their default manner. The result is shown in the image below:

CustomDrawTreeButton_manual

using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Events;

private void vGridControl1_CustomDrawTreeButton(object sender, 
CustomDrawTreeButtonEventArgs e) {
   if (e.TreeButtonType == TreeButtonType.ExplorerBarButton) return;
   Color bkColor;
   if (e.Row == vGridControl1.FocusedRow)
       bkColor = Color.White;
   else
       bkColor = Color.Blue;

   if (e.Expanded)
       e.Graphics.FillPolygon(new SolidBrush(bkColor), new PointF[]{   
            new PointF(e.Bounds.X, e.Bounds.Y),
            new PointF(e.Bounds.X + e.Bounds.Width, e.Bounds.Y),
            new PointF(e.Bounds.X + e.Bounds.Width / 2, e.Bounds.Y + e.Bounds.Height)});
   else
       e.Graphics.FillPolygon(new SolidBrush(bkColor), new PointF[]{   
            new PointF(e.Bounds.X, e.Bounds.Y),
            new PointF(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height / 2),
            new PointF(e.Bounds.X, e.Bounds.Y + e.Bounds.Height)});
   e.Handled = true;
}
See Also