Skip to main content
All docs
V24.2

TreeList.CustomizeNodeTemplate Event

Allows you to customize templated nodes.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.2.dll

Declaration

[DXCategory("Events")]
public event CustomizeNodeHtmlEventHandler CustomizeNodeTemplate

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.
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);
    }
}
See Also