windowsforms-devexpress-dot-xtratreelist-76210105.md
Provides data for the TreeList.CreateCustomNode event.
Namespace : DevExpress.XtraTreeList
Assembly : DevExpress.XtraTreeList.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
public class CreateCustomNodeEventArgs :
EventArgs
Public Class CreateCustomNodeEventArgs
Inherits EventArgs
CreateCustomNodeEventArgs is the data class for the following events:
The TreeList.CreateCustomNode event is fired when a new node is added to a Tree List and provides the opportunity to create custom nodes (TreeListNode descendants) and add them to a Tree List. The CreateCustomNodeEventArgs class provides the CreateCustomNodeEventArgs.Node property which represents the added node. The collection of nodes to which the added node belongs and the node’s unique identifier are represented by the CreateCustomNodeEventArgs.Owner and CreateCustomNodeEventArgs.NodeID properties, respectively.
CreateCustomNodeEventArgs objects are automatically created and passed to TreeList.CreateCustomNode event handlers.
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; }
}
}
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraTreeList.Nodes.Operations
Private Sub TreeList1_CreateCustomNode(ByVal sender As Object, _
ByVal e As CreateCustomNodeEventArgs) Handles TreeList1.CreateCustomNode
e.Node = New CustomTLNode(e.NodeID, e.Owner)
End Sub
' ...
Public Class CustomTLNode
Inherits TreeListNode
Public Sub New(ByVal id As Integer, ByVal owner As TreeListNodes)
MyBase.New(id, owner)
End Sub
Public ReadOnly Property ChildNodesCount() As Integer
Get
If Me.TreeList Is Nothing Then
Return -1
End If
Dim operation As New NodesCountOperation()
Me.TreeList.NodesIterator.DoLocalOperation(operation, Me.Nodes)
Return operation.Result
End Get
End Property
End Class
Public Class NodesCountOperation
Inherits TreeListOperation
Dim _result As Integer
Public Sub New()
_result = 0
End Sub
Public Overrides Sub Execute(ByVal node As TreeListNode)
_result += 1
End Sub
Public ReadOnly Property Result() As Integer
Get
Return _result
End Get
End Property
End Class
Object EventArgs CreateCustomNodeEventArgs
See Also