TreeList.CreateCustomNode Event

Provides the ability to create custom nodes.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v20.1.dll

Declaration

public event CreateCustomNodeEventHandler CreateCustomNode
Public Event CreateCustomNode As CreateCustomNodeEventHandler

Event Data

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

Property Description
Node Gets or sets a value which represents the created node.
NodeID Gets the node's unique identifier.
Owner Gets the collection of nodes which owns the created node.
Tag Gets the data associated with the Tree List node via the constructor.

Remarks

The CreateCustomNode event fires when a new node is added to a Tree List. Handle this event to add custom nodes (TreeListNode descendants).

To add a custom node to the Tree List, the node should be assigned to the event parameter's CreateCustomNodeEventArgs.Node property which represents the added node. The CreateCustomNodeEventArgs.NodeID and CreateCustomNodeEventArgs.Owner properties represent the node's unique identifier and the collection of nodes to which the added node belongs, respectively.

Examples

The following example handles the TreeList.CreateCustomNode event to add custom nodes to the Tree List. Custom nodes are represented by the CustomTLNode class which extends the functionality of the TreeListNode class. It introduces the ChildNodesCount property which returns the total number of nodes owned by the current node.

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

private void treeList1_CreateCustomNode(object sender, CreateCustomNodeEventArgs e) {
   e.Node = new CustomTLNode(e.NodeID, e.Owner);
}
// ...
public class CustomTLNode : TreeListNode {
   public CustomTLNode(int id, TreeListNodes owner) : base(id, owner) {}
   public int ChildNodesCount {
      get {
         if(this.TreeList == null) return -1;
         NodesCountOperation operation = new NodesCountOperation();
         this.TreeList.NodesIterator.DoLocalOperation(operation, this.Nodes);
         return operation.Result;
      }
   }
}
public class NodesCountOperation : TreeListOperation {
   private int result;
   public NodesCountOperation() {
      result = 0;
   }
   public override void Execute(TreeListNode node) {
      result++;
   }
   public int Result {
      get { return result; }
   }
}
See Also