VGridControlBase.CustomDrawTreeButton Event

Enables expand buttons to be painted manually.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v20.1.dll

Declaration

public event CustomDrawTreeButtonEventHandler CustomDrawTreeButton
Public Event CustomDrawTreeButton As CustomDrawTreeButtonEventHandler

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.

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

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 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) {
   VGridControl grid = sender as VGridControl;
    if(e.TreeButtonType == TreeButtonType.ExplorerBarButton) return;

    Color bkColor = e.Row == grid.FocusedRow ? Color.White : Color.Blue;
    if(e.Expanded)
        e.Cache.FillPolygon(new Point[]{ e.Bounds.Location,
    new Point(e.Bounds.Right, e.Bounds.Y),
    new Point(e.Bounds.X + e.Bounds.Width / 2, e.Bounds.Bottom) }, bkColor);
    else
        e.Cache.FillPolygon(new Point[]{ e.Bounds.Location,
    new Point(e.Bounds.Right, e.Bounds.Y + e.Bounds.Height / 2),
    new Point(e.Bounds.X, e.Bounds.Bottom) }, bkColor);
    e.Handled = true;
}
See Also