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