Back to Devexpress

TreeList.CustomDrawEmptyArea Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-c89781ca.md

latest9.7 KB
Original Source

TreeList.CustomDrawEmptyArea Event

Enables you to custom paint a Tree List’s empty area.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
[DXCategory("CustomDraw")]
public event CustomDrawEmptyAreaEventHandler CustomDrawEmptyArea
vb
<DXCategory("CustomDraw")>
Public Event CustomDrawEmptyArea As CustomDrawEmptyAreaEventHandler

Event Data

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

PropertyDescription
AppearanceGets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
BehindColumnGets the blank column’s bounding rectangle.
BoundsGets the painted element’s bounding rectangle. Inherited from CustomDrawEventArgs.
CacheGets an object specifying the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs.
EmptyAreaRegionUse the EmptyRectangles property to get the region occupied by the empty area.
EmptyRectanglesGets the array of rectangles that specify the empty area.
EmptyRowsGets the bounding rectangle occupied by the empty rows.
GraphicsGets an object used to paint. Inherited from CustomDrawEventArgs.
HandledGets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs.
IsRightToLeftGets a value indicating whether the TreeList’s elements are aligned to support locales using right-to-left fonts. Inherited from CustomDrawEventArgs.
ObjectArgsGets an object containing information about the painted element. Inherited from CustomDrawEventArgs.
PainterGets the painter object that provides the default element’s painting mechanism. Inherited from CustomDrawEventArgs.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Performs default painting of an element. Inherited from CustomDrawEventArgs.
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from CustomDrawEventArgs.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. Inherited from CustomDrawEventArgs.

Remarks

Handle the CustomDrawEmptyArea event to custom paint the control’s empty area(the area where Tree List nodes are going to be displayed).

See the Custom Draw Scenarios topic for information on using custom draw events.

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 code handles the TreeList.CustomDrawEmptyArea event to manually paint the control’s empty area when no nodes are displayed.

The image below shows the result.

csharp
using DevExpress.XtraTreeList;

private void treeList1_CustomDrawEmptyArea(object sender, CustomDrawEmptyAreaEventArgs e) {
    if (treeList1.Nodes.Count > 1) return;
    string s = "No Records Available";
    e.Appearance.FontStyleDelta = FontStyle.Bold;
    e.Appearance.FontSizeDelta = 2;
    e.Cache.DrawString(s, e.Appearance.Font, e.Cache.GetSolidBrush(Color.Black), e.Bounds);
    e.Handled = true;
}
vb
Imports DevExpress.XtraTreeList

Private Sub TreeList1_CustomDrawEmptyArea(sender As Object, e As DevExpress.XtraTreeList.CustomDrawEmptyAreaEventArgs) Handles TreeList1.CustomDrawEmptyArea
    If TreeList1.Nodes.Count > 1 Then Return
    Dim s As String = "No Records Available"
    e.Appearance.FontStyleDelta = FontStyle.Bold
    e.Appearance.FontSizeDelta = 2
    e.Cache.DrawString(s, e.Appearance.Font, e.Cache.GetSolidBrush(Color.Black), e.Bounds)
    e.Handled = True
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawEmptyArea event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/TreeList/TreeListItemControlProvider.cs#L28

csharp
tree.CustomColumnDisplayText += Tree_CustomColumnDisplayText;
tree.CustomDrawEmptyArea += Tree_CustomDrawEmptyArea;
tree.OptionsView.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/TreeList/TreeListItemControlProvider.vb#L32

vb
AddHandler tree.CustomColumnDisplayText, AddressOf Tree_CustomColumnDisplayText
AddHandler tree.CustomDrawEmptyArea, AddressOf Tree_CustomDrawEmptyArea
tree.OptionsView.FocusRectStyle = DrawFocusRectStyle.RowFullFocus

See Also

CustomDrawNodeIndicator

CustomDrawRowFooter

CustomDrawRowFooterCell

CustomDrawFooter

CustomDrawFooterCell

Custom Drawing

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace