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

Treeview add node problem

P: n/a
Hi all, I have a treenode control and I would like to add a node in a
certain level as child. For example I know that with this code I can add a
level one node plus a level two node:

-------------------
Dim node As TreeNode
node = TreeView1.Nodes.Add("Level one node")
node.Nodes.Add("Level two node")
-------------------

Well, at this point is possible to add a child node at that "level two node"
with code? (whitout select it with the mouse, just with code )

Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
In article <#m**************@tk2msftngp13.phx.gbl>, poldoj wrote:
Hi all, I have a treenode control and I would like to add a node in a
certain level as child. For example I know that with this code I can add a
level one node plus a level two node:

-------------------
Dim node As TreeNode
node = TreeView1.Nodes.Add("Level one node")
node.Nodes.Add("Level two node")
-------------------

Well, at this point is possible to add a child node at that "level two node"
with code? (whitout select it with the mouse, just with code )


TreeView1.Nodes(0).Nodes.Add ("Another node")

Is that what your looking for? Or am I misunderstanding the question?

--
Tom Shelton [MVP]
Nov 21 '05 #2

P: n/a
First of all, thanks for your reply Tom Shelton [MVP], I tried that code
-----
TreeView1.Nodes(0).Nodes.Add ("Another node")
-----

It just act like node.Nodes.Add("Level two node")
and if put a 1 instead of 0 an "out of range exception is throwed".
I need to add a level 3 node at an preexistent level 2, sorry for my bad
englsh. Example
---------
level 1
level 2a
level 2b
level 2c
level 3
---------

Its possible to add that "level 3" with code? I know that if I select with
the mouse "level 2c" than is possible to use

Dim node01 As New TreeNode

node01 = TreeView1.SelectedNode

node01.Nodes.Add("node added")

--------------
Nov 21 '05 #3

P: n/a
In article <e6**************@TK2MSFTNGP15.phx.gbl>, poldoj wrote:
First of all, thanks for your reply Tom Shelton [MVP], I tried that code
-----
TreeView1.Nodes(0).Nodes.Add ("Another node")
-----

It just act like node.Nodes.Add("Level two node")
and if put a 1 instead of 0 an "out of range exception is throwed".
I need to add a level 3 node at an preexistent level 2, sorry for my bad
englsh. Example
---------
level 1
level 2a
level 2b
level 2c
level 3
---------

Its possible to add that "level 3" with code? I know that if I select with
the mouse "level 2c" than is possible to use

Dim node01 As New TreeNode

node01 = TreeView1.SelectedNode

node01.Nodes.Add("node added")

--------------


treeview1.Nodes (0).Nodes(2).Nodes.Add ("level 3")

--
Tom Shelton [MVP]
Nov 21 '05 #4

P: n/a
"poldoj" <po********@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I know that with this code I can add a level one node plus a level
two node:

Dim node As TreeNode
node = TreeView1.Nodes.Add("Level one node")
node.Nodes.Add("Level two node")

Well, at this point is possible to add a child node at that "level two
node" with code?


Just extend what you've got, remembering that whenever you
call Nodes.Add(), you get the a reference to the Node that after it
has been added, so

Dim level1 As TreeNode
Dim level2 As TreeNode
Dim level3 As TreeNode

level1 = TreeView1.Nodes.Add("Level one node")
level2 = level1.Nodes.Add( "Level two node" )
level3 = level2.Nodes.Add( "Level three node" )

That's fine, so long as you're only adding to the node you processed
last. If you need to find an arbitrary node that's already /in/ the
TreeView and add a new child node to /that/, it's just a little more
complicated, since the TreeView (unlike its VB "proper" predecessor)
doesn't expose any sort of "key" for each Node by which you could
access any Node directly.

HTH,
Phill W.
Nov 21 '05 #5

P: n/a
dear Phill. W, thanks for your reply. Indeed is exactly that I mean. I have
an "already-in-the-treeview" node, and then I would like to add a child at
that node. Not so easy task to accomplish after your words :(

<quote>it's just a little more
complicated, since the TreeView...</quote>
Thanks however

"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> ha scritto nel messaggio
news:de**********@yarrow.open.ac.uk... "poldoj" <po********@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I know that with this code I can add a level one node plus a level
two node:

Dim node As TreeNode
node = TreeView1.Nodes.Add("Level one node")
node.Nodes.Add("Level two node")

Well, at this point is possible to add a child node at that "level two
node" with code?


Just extend what you've got, remembering that whenever you
call Nodes.Add(), you get the a reference to the Node that after it
has been added, so

Dim level1 As TreeNode
Dim level2 As TreeNode
Dim level3 As TreeNode

level1 = TreeView1.Nodes.Add("Level one node")
level2 = level1.Nodes.Add( "Level two node" )
level3 = level2.Nodes.Add( "Level three node" )

That's fine, so long as you're only adding to the node you processed
last. If you need to find an arbitrary node that's already /in/ the
TreeView and add a new child node to /that/, it's just a little more
complicated, since the TreeView (unlike its VB "proper" predecessor)
doesn't expose any sort of "key" for each Node by which you could
access any Node directly.

HTH,
Phill W.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.