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. Visual Basic
  4. VB.Net add child node to treeview control

VB.Net add child node to treeview control

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdata-structures
5 Posts 2 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.
  • M Offline
    M Offline
    Mbire
    wrote on last edited by
    #1

    Hi dudes, In VB6 we could add a child node to a treeview control by specifying a key for an existing node, then a relationship then the new node to be added to the tree. How can i do something like that in vb.net, given that from the add method of the .net treeview there isn't even one thats requiring the parent key and relationship? Thanks spans in advance:confused:

    T 1 Reply Last reply
    0
    • M Mbire

      Hi dudes, In VB6 we could add a child node to a treeview control by specifying a key for an existing node, then a relationship then the new node to be added to the tree. How can i do something like that in vb.net, given that from the add method of the .net treeview there isn't even one thats requiring the parent key and relationship? Thanks spans in advance:confused:

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      dim tnode as new treenode("text") ' is the main node treeview.nodes.add(tnode) dim tsubnode as new treenode("text") ' is the subnode tnode.nodes.add(tsubnode) this should give you 1 main node with 1 subnode hope this helps

      M 1 Reply Last reply
      0
      • T Tom Deketelaere

        dim tnode as new treenode("text") ' is the main node treeview.nodes.add(tnode) dim tsubnode as new treenode("text") ' is the subnode tnode.nodes.add(tsubnode) this should give you 1 main node with 1 subnode hope this helps

        M Offline
        M Offline
        Mbire
        wrote on last edited by
        #3

        Thanks TDDragon for your reply, The thing is I do not know the depth of the tree before-hand and I am adding the child nodes recursively, its a something like an explorer program. So i would need to add whatever child node to any parent whose key i know:|

        T 1 Reply Last reply
        0
        • M Mbire

          Thanks TDDragon for your reply, The thing is I do not know the depth of the tree before-hand and I am adding the child nodes recursively, its a something like an explorer program. So i would need to add whatever child node to any parent whose key i know:|

          T Offline
          T Offline
          Tom Deketelaere
          wrote on last edited by
          #4

          if you go tru it parent node by parent node you can do it like folowing: dim tnode as treenode() dim subnode as treenode() if "check the node you need to add" = "parent node" then tnode = new treenode("text") treeview.nodes.add(tnode) else subnode = new treenode("text") tnode.nodes.add(subnode) end if remember this will only work if you make you'r treeview parentnode by parentnode if not (you need to add a node to parentnode1 while you already created parentnode3) then maybe this might be some help 'first create alle parent nodes and give the tag property a key value 'then iterate true you're parent nodes and where node.tag = key add a subnode for each t as treenode in treeview.nodes if t.tag = key then dim subnode as new treenode("text") t.nodes.add(subnode) end if loop this way will take more time so if possible I would recomend the first way hope this helps

          M 1 Reply Last reply
          0
          • T Tom Deketelaere

            if you go tru it parent node by parent node you can do it like folowing: dim tnode as treenode() dim subnode as treenode() if "check the node you need to add" = "parent node" then tnode = new treenode("text") treeview.nodes.add(tnode) else subnode = new treenode("text") tnode.nodes.add(subnode) end if remember this will only work if you make you'r treeview parentnode by parentnode if not (you need to add a node to parentnode1 while you already created parentnode3) then maybe this might be some help 'first create alle parent nodes and give the tag property a key value 'then iterate true you're parent nodes and where node.tag = key add a subnode for each t as treenode in treeview.nodes if t.tag = key then dim subnode as new treenode("text") t.nodes.add(subnode) end if loop this way will take more time so if possible I would recomend the first way hope this helps

            M Offline
            M Offline
            Mbire
            wrote on last edited by
            #5

            Thanks man, used the 2nd one coz i ended up having to 'lazy-load' the tree. thanks spans:-D

            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