| |
 |
How to: Iterate through nodes and collapse specific nodes
The following example shows how to create an operation class that will collapse all the nodes which do not contain the specified node as their child. Only the node's parents will be expanded as a result.
The operation class accepts the node as its constructor parameter and stores it in an internal variable. The Execute method checks whether the processed node contains the specified node as a child. If not, the processed node is collapsed. The operation class also overrides the TreeListOperation.NeedsFullIteration property to process only the nodes that have children. This provides performance benefits when working with large and complex node structures.
The image below shows the Tree List before and after executing the sample code:

C# |
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList.Nodes.Operations;
public class CollapseExceptSpecifiedOperation : TreeListOperation {
TreeListNode visibleNode;
public CollapseExceptSpecifiedOperation(TreeListNode visibleNode) : base() {
this.visibleNode = visibleNode;
}
public override void Execute(TreeListNode node) {
if (!visibleNode.HasAsParent(node))
node.Expanded = false;
}
public override bool NeedsFullIteration { get { return false; } }
}
treeList1.NodesIterator.DoOperation(new CollapseExceptSpecifiedOperation(treeList1.FocusedNode));
|
VB |
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraTreeList.Nodes.Operations
Public Class CollapseExceptSpecifiedOperation
Inherits TreeListOperation
Private visibleNode As TreeListNode
Public Sub New(ByVal visibleNode As TreeListNode)
Me.visibleNode = visibleNode
End Sub
Public Overrides Sub Execute(ByVal node As TreeListNode)
If Not visibleNode.HasAsParent(node) Then
node.Expanded = False
End If
End Sub
Public Overrides ReadOnly Property NeedsFullIteration() As Boolean
Get
Return False
End Get
End Property
End Class
TreeList1.NodesIterator.DoOperation(New CollapseExceptSpecifiedOperation(TreeList1.FocusedNode))
|
Is this topic helpful?
Additional Feedback
Close
|