Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TreeNodes

TreeNodes

Scheduled Pinned Locked Moved C#
question
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PHDENG81
    wrote on last edited by
    #1

    I have a recursive call to a treeview as such: foreach (TreeNode n in nodes) { do something } How can I get this to work fall all nodes except the TopNode? Thanks in Advance. D

    D 1 Reply Last reply
    0
    • P PHDENG81

      I have a recursive call to a treeview as such: foreach (TreeNode n in nodes) { do something } How can I get this to work fall all nodes except the TopNode? Thanks in Advance. D

      D Offline
      D Offline
      deep7
      wrote on last edited by
      #2

      instead of foreach(treenode n in nodes) { } u cld do the coding wotever u wanna do.."for those levels".. so in tat case, u cld not do it for the topnode level.. i guess this shld do.. try it..

      G 1 Reply Last reply
      0
      • D deep7

        instead of foreach(treenode n in nodes) { } u cld do the coding wotever u wanna do.."for those levels".. so in tat case, u cld not do it for the topnode level.. i guess this shld do.. try it..

        G Offline
        G Offline
        g00fyman
        wrote on last edited by
        #3

        create your root node then call the recursive function to return a treenode collection with root as parent as all nodes can be a subtree, this can also work by recursilvely calling itself and returning a subtree with its caller as the root, eventually the root(top initial root) node will end up with all subtrees as its children have just finished a similar problem to this, gotta love recursion :-) regards, g00fy

        P 1 Reply Last reply
        0
        • G g00fyman

          create your root node then call the recursive function to return a treenode collection with root as parent as all nodes can be a subtree, this can also work by recursilvely calling itself and returning a subtree with its caller as the root, eventually the root(top initial root) node will end up with all subtrees as its children have just finished a similar problem to this, gotta love recursion :-) regards, g00fy

          P Offline
          P Offline
          PHDENG81
          wrote on last edited by
          #4

          Thanks for your help. But how do I return the root as the parent? the root node is displayed when the form is generated. However, there are no child nodes until the user drags-and-drops to the corresponding treeview. Thanks again.

          G 1 Reply Last reply
          0
          • P PHDENG81

            Thanks for your help. But how do I return the root as the parent? the root node is displayed when the form is generated. However, there are no child nodes until the user drags-and-drops to the corresponding treeview. Thanks again.

            G Offline
            G Offline
            g00fyman
            wrote on last edited by
            #5

            i thought you wanted to exclude the root node, that is the initial root node. you should just be adding to it with your recursive call like rootNode.Nodes.Add(GetSubTree()); if you want the root, the easiest way is to code it and hold a reference to it ... or ... get it from tree.Nodes collection hth g00fy

            P 1 Reply Last reply
            0
            • G g00fyman

              i thought you wanted to exclude the root node, that is the initial root node. you should just be adding to it with your recursive call like rootNode.Nodes.Add(GetSubTree()); if you want the root, the easiest way is to code it and hold a reference to it ... or ... get it from tree.Nodes collection hth g00fy

              P Offline
              P Offline
              PHDENG81
              wrote on last edited by
              #6

              Thanks for the speedy response. You were right, I want to exclude the topnode or root node. I want to make changes to all of the child nodes, not the topnode. How will adding the GetSubTree exclude the topnode? Thanks again for all of your help.

              G 1 Reply Last reply
              0
              • P PHDENG81

                Thanks for the speedy response. You were right, I want to exclude the topnode or root node. I want to make changes to all of the child nodes, not the topnode. How will adding the GetSubTree exclude the topnode? Thanks again for all of your help.

                G Offline
                G Offline
                g00fyman
                wrote on last edited by
                #7

                get subtree is your recursive call that is building the subtree/s then you add that to the node collection of the rootnode just a quick eg of top of head private TreeNode root; public void Test() { root = new TreeNode("root"); root.Nodes.Add(GetSubTree()); this.treeView1.Nodes.Add(root); } int i = 0; private TreeNode GetSubTree() { TreeNode subtree = new TreeNode("x: " + i); while(i++ < 10) { root.Nodes.Add(new TreeNode("node: " + i)); return GetSubTree(); } return subtree; } hth g00fy

                P 1 Reply Last reply
                0
                • G g00fyman

                  get subtree is your recursive call that is building the subtree/s then you add that to the node collection of the rootnode just a quick eg of top of head private TreeNode root; public void Test() { root = new TreeNode("root"); root.Nodes.Add(GetSubTree()); this.treeView1.Nodes.Add(root); } int i = 0; private TreeNode GetSubTree() { TreeNode subtree = new TreeNode("x: " + i); while(i++ < 10) { root.Nodes.Add(new TreeNode("node: " + i)); return GetSubTree(); } return subtree; } hth g00fy

                  P Offline
                  P Offline
                  PHDENG81
                  wrote on last edited by
                  #8

                  Thanks for your help Goofy. Have a good one.

                  G 1 Reply Last reply
                  0
                  • P PHDENG81

                    Thanks for your help Goofy. Have a good one.

                    G Offline
                    G Offline
                    g00fyman
                    wrote on last edited by
                    #9

                    no problem, hopefully i was some help :) regards, g00fy

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups