By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

adding a node to a parent node in a tree view

P: n/a
If i already have a tree view created, and want to add another new node to
it, how would i do so? Is there a way to throught tags or anything? like i
have this

RootNode
|
+-- Child 1
+-- Child 2

and i want to add a child node to child 1 how would i refrence it and add a
new one to it after the list was already made? thanks (each node is getting
a name and a tag during the initial creation)
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello Brian

To add children to a node you have to get a reference to the node you want
to add children to then use the Nodes.Add methof of the node. The code
below adds three levels of nodes using for-next loops. It should provide
youy with a demonstration of how to populate a treeview
Dim TopNode As TreeNode

Dim SecondNode As TreeNode

Dim ThirdNode As TreeNode

With Me.TreeView1

For MyCount1 As Integer = 0 To 5

'adds top level node

TopNode = .Nodes.Add("TopNode" & MyCount1)

For MyCount2 As Integer = 0 To 5

'adds second level node

SecondNode = TopNode.Nodes.Add("SecondLevelNode" & MyCount2)

For MyCount3 As Integer = 0 To 5

'adds third level node

SecondNode.Nodes.Add("ThirdLevelNode" & MyCount3)

Next

Next

Next

End With


--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
If i already have a tree view created, and want to add another new node to
it, how would i do so? Is there a way to throught tags or anything? like i
have this

RootNode
|
+-- Child 1
+-- Child 2

and i want to add a child node to child 1 how would i refrence it and add a new one to it after the list was already made? thanks (each node is getting a name and a tag during the initial creation)

Nov 20 '05 #2

P: n/a
yes that I know, but if I am dynamically adding new nodes after it has been
initially built how would i find a node in the tree that I am looking for
and preform an add to its node colletion?
"IbrahimMalluf" <Ib*****@malluf.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
Hello Brian

To add children to a node you have to get a reference to the node you want
to add children to then use the Nodes.Add methof of the node. The code
below adds three levels of nodes using for-next loops. It should provide
youy with a demonstration of how to populate a treeview
Dim TopNode As TreeNode

Dim SecondNode As TreeNode

Dim ThirdNode As TreeNode

With Me.TreeView1

For MyCount1 As Integer = 0 To 5

'adds top level node

TopNode = .Nodes.Add("TopNode" & MyCount1)

For MyCount2 As Integer = 0 To 5

'adds second level node

SecondNode = TopNode.Nodes.Add("SecondLevelNode" & MyCount2)

For MyCount3 As Integer = 0 To 5

'adds third level node

SecondNode.Nodes.Add("ThirdLevelNode" & MyCount3)

Next

Next

Next

End With


--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
If i already have a tree view created, and want to add another new node to it, how would i do so? Is there a way to throught tags or anything? like i have this

RootNode
|
+-- Child 1
+-- Child 2

and i want to add a child node to child 1 how would i refrence it and
add a
new one to it after the list was already made? thanks (each node is

getting
a name and a tag during the initial creation)


Nov 20 '05 #3

P: n/a
You can recursively iterate through the nodes (starting at the root), and
then just find that matching tag or text or whatever.

node find (string tofind, node root)
if root has children
return find(tofind, root.nodes(0))
else
if root.tag = tofind then
return root
end if
end if
end function

something like that pseudo code.

--
Regards,
Webster

"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:eg**************@tk2msftngp13.phx.gbl...
If i already have a tree view created, and want to add another new node to
it, how would i do so? Is there a way to throught tags or anything? like i
have this

RootNode
|
+-- Child 1
+-- Child 2

and i want to add a child node to child 1 how would i refrence it and add a new one to it after the list was already made? thanks (each node is getting a name and a tag during the initial creation)

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.