Results 1 to 3 of 3

Thread: how to write this code recursive

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2024
    Posts
    72

    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

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    12,090

    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:
    1. Call expand on the argument
    2. Loop over any children
    3. 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
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2024
    Posts
    72

    Re: how to write this code recursive

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width