-
Apr 4th, 2024, 09:24 AM
#1
Thread Starter
Lively Member
how to write this code recursive
Hello,
how can i write this code recursive?
Code:
If Flag2 = True Then
Root.Expand()
For i = 0 To RootNodes.Count - 1
RootNodes.Item(i).Expand()
Dim RootItemsfori = Root.Nodes.Item(i).Nodes
For j = 0 To RootItemsfori.Count - 1
RootItemsfori.Item(j).Expand()
Dim RootItemsforj = Root.Nodes.Item(i).Nodes.Item(j).Nodes
For k = 0 To RootItemsforj.Count - 1
RootItemsforj.Item(k).Expand()
Dim RootItemsforw = Root.Nodes.Item(i).Nodes.Item(j).Nodes.Item(k).Nodes
For w = 0 To RootItemsforw.Count - 1
Dim cNI = TryCast(RootItemsforw.Item(w).Tag, RiskeySIITreeBuilder.NodeInfo)
If Not cNI.Key.UnterStArt.Value.ToString() Is Nothing Then
RootItemsforw.Item(w).Expand()
Else
Exit Sub
End If
Next
Next
Next
Next
-
Apr 4th, 2024, 09:30 AM
#2
Re: how to write this code recursive
So you want to call the expand method on the parent element and all of its children? If so, create a method that accepts a single argument for the root TreeNode and inside the method:
- Call expand on the argument
- Loop over any children
- Recursively call the method on the child node
Here is an example:
Code:
Private Shared Sub RecursivelyExpandTreeNode(root As TreeNode)
root.Expand()
For Each child In root.Nodes
RecursivelyExpandTreeNode(child)
Next
End Sub
-
Apr 4th, 2024, 09:44 AM
#3
Thread Starter
Lively Member
Re: how to write this code recursive
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|