Back to Devexpress

TreeList.CustomizeNodeTemplate Event

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

latest3.4 KB
Original Source

TreeList.CustomizeNodeTemplate Event

Allows you to customize templated nodes.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
[DXCategory("Events")]
public event CustomizeNodeHtmlEventHandler CustomizeNodeTemplate
vb
<DXCategory("Events")>
Public Event CustomizeNodeTemplate As CustomizeNodeHtmlEventHandler

Event Data

The CustomizeNodeTemplate event's data class is DevExpress.XtraTreeList.CustomizeNodeHtmlEventArgs.

Remarks

The WinForms TreeList control supports HTML/CSS templates and allows you to generate unique custom layouts for nodes. The TreeList control fires the CustomizeNodeTemplate event for each templated node before it is displayed and allows you to customize HTML elements.

Use the e.Element event parameter to access HTML elements of the currently processed item. The following methods allow you to retrieve HTML elements by tag, class, and ID:

  • Element.FindElementsByTag — Returns a list of HTML elements that have the specified tag.
  • Element.FindElementsByClass — Returns a list of HTML elements that are of the specified class.
  • Element.FindElementById — Returns an HTML element with the specified ID.

The elements returned by these methods expose properties to change element display settings. The main properties include:

  • HtmlElement.Hidden — Allows you to hide (collapse) the element.

  • HtmlElement.Disabled — Allows you to disable the element.

  • HtmlElement.Style — Allows you to modify CSS style properties applied to the element. This object exposes the SetBackgroundColor, SetForeColor, SetVisibility (displays an empty region instead of the element), and SetProperty methods for this purpose.

  • C#

  • VB.NET

csharp
string[] friendList = new string[] {
    "John Heart",
    "Kelly Rodriguez"
};

void TreeList1_CustomizeNodeTemplate(object sender, CustomizeNodeHtmlEventArgs e) {
    var authorField = (string)e.Node["Author"];
    if (friendList.Contains(authorField)) {
        var element = e.Element.FindElementsByClass("author").Single();
        element.Style.SetForeColor(Color.Green);
    }
}
vb
Option Infer On

Private friendList() As String = { "John Heart", "Kelly Rodriguez" }

Private Sub TreeList1_CustomizeNodeTemplate(ByVal sender As Object, ByVal e As CustomizeNodeHtmlEventArgs)
    Dim authorField = CStr(e.Node("Author"))
    If friendList.Contains(authorField) Then
        Dim element = e.Element.FindElementsByClass("author").Single()
        element.Style.SetForeColor(Color.Green)
    End If
End Sub

See Also

HtmlTemplates

QueryNodeTemplate

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace