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

TreeListNode Class

Represents a node of the Tree List control.

Namespace: DevExpress.XtraTreeList.Nodes

Assembly: DevExpress.XtraTreeList.v18.2.dll

Declaration

public class TreeListNode :
    ICloneable

The following members return TreeListNode objects:

Show 62 links

Remarks

Tree List nodes are organized in a hierarchical structure using parent-child relationships. Every node can have child nodes stored in the TreeListNode.Nodes collection.

The TreeList.Nodes property maintains a collection of root nodes. These nodes are located at the zero level of the hierarchy (their TreeListNode.Level property returns 0). They do not have parents and thus their TreeListNode.ParentNode property returns null (Nothing in Visual Basic). The children of root nodes reside at a level of 1, their children reside at a level of 2 and so on.

Tree List nodes can be expanded to display the next level of child nodes. An end-user can expand a node by pressing its plus (+) button (if it is displayed). In code, you can expand a node by setting the TreeListNode.Expanded property to true. Setting the property to false hides child nodes. When the node is expanded or collapsed the following events are generated: TreeList.BeforeExpand, TreeList.AfterExpand and TreeList.BeforeCollapse, TreeList.AfterCollapse.

The TreeListNode.HasChildren property specifies whether the node has children. You can manually set the property to true to display a plus (+) button within the node (ensure that the TreeListOptionsView.ShowButtons option is enabled). An end-user can press it and thus generate the TreeList.BeforeExpand event. This can be used to implement node dynamic loading. Please refer to the How to: Implement Virtual Mode (Dynamic Loading) in Unbound Mode topic for details.

You can display up to two images in nodes. Assign image lists to the TreeList.SelectImageList and TreeList.StateImageList properties for this purpose. There are a number of ways images can be assigned to individual nodes. Refer to the description of the following members for details: TreeList.ImageIndexFieldName, TreeListNode.SelectImageIndex, TreeListNode.StateImageIndex, TreeList.GetSelectImage and TreeList.GetStateImage.

The Tree List provides support for node drag-and-drop in the current control and even to another Tree List control. By default, when moving a node to another position it becomes a child of the target node. If the SHIFT key is pressed, the dragged node is dropped before the target node.

To enable node drag-and-drop, use the TreeListOptionsDragAndDrop.DragNodesMode property. For information on node drag-and-drop to another Tree List control, see TreeList.CustomizeNewNodeFromOuterData. You can control drag-and-drop operations by handling the TreeList.BeforeDragNode, TreeList.AfterDragNode, TreeList.DragCancelNode and TreeList.CustomizeNewNodeFromOuterData events.

It is possible to create your own nodes that override the default behavior. The following public members can be overridden: TreeListNode.GetDisplayText, TreeListNode.Data, TreeListNode.Expanded, TreeListNode.HasChildren, TreeListNode.Item. To use your own nodes, it is necessary to create a descendant of the TreeList class and override the protected TreeList.CreateNode method.

Example

The following sample code implements the custom node to be used in the Tree List control. The CreateNode method of the TreeList class is overridden to use the created node descendant.

The MyNode class is derived from the TreeListNode to allow assigning custom heights to nodes. The Height property is declared for this purpose.

The MyTreeList class is derived from TreeList to use the custom node within the Tree List control. The RaiseCalcNodeHeight method is overridden to assign node heights with respect to the Height property of custom nodes.

After the code has been written you can use the Tree List descendant in your applications.

using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;

public class MyNode : TreeListNode {
   protected int heightCore;
   // using the inherited constructor to initialize the node
   // and assigning the default value to the Height property
   public MyNode(int id, TreeListNodes owner) : base(id, owner) {
      this.heightCore = -1;
   }
   // specifies the height of an individual node
   public int Height {
      get { return heightCore; }
      set {
         if(value < -1) return;
         if(value > -1 && value < 6) value = 6;
         if(Height != value) {
            heightCore = value;
            if(TreeList != null)
               TreeList.LayoutChanged();
         }
      }
   }
}
public class MyTreeList : TreeList {
   public MyTreeList() {
      // disabling automatic node height calculations
      this.OptionsBehavior.AutoNodeHeight = false;
   }
   // overriding the CreateNode method to use custom nodes
   protected override TreeListNode CreateNode(int nodeID, TreeListNodes owner, object tag) {
      return new MyNode(nodeID, owner);
   }
   // overriding the method that calculated the height of a node
   // assigning the height of the processed node as specified by its Height property
   protected override void RaiseCalcNodeHeight(TreeListNode node, ref int nodeHeight) {
      MyNode _myNode = node as MyNode;
      if(_myNode != null) {
         nodeHeight = _myNode.Height;
      }
      else base.RaiseCalcNodeHeight(node, ref nodeHeight);
   }
}

Inheritance

Object
TreeListNode
See Also