|
-
Jan 1st, 2006, 04:00 AM
#1
Thread Starter
Giants World Champs!!!!
[RESOLVED] Adding a Node to a Child Node - How?
I am adding a child node (Node 1) to a treeview and then I want to add a Child Node (Node 2) to the newly added child node (Node 1):
VB Code:
AddChild(Selectednode, "John Doe", 12) 'Adding Node1
intNodeNum = TreeView1.Nodes(0).Nodes.Count + 1 ' I am attempting to get the
' index of last added node
Selectednode = TreeView1.Nodes(0).Nodes(intNodeNum) ' <== I get an error on this line
AddChild(Selectednode, "Address", 13) ' <==Node 2
How do I do this?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 1st, 2006, 04:13 AM
#2
Thread Starter
Giants World Champs!!!!
Re: Adding a Node to a Child Node - How?
I tried using the following:
VB Code:
TreeView1.SelectedNode = TreeView1.Nodes(0).PrevNode
Thinking that it would given me the index of the last node added (Node 1) but no dice.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 1st, 2006, 04:21 AM
#3
Re: Adding a Node to a Child Node - How?
 Originally Posted by Mark Gambo
I am adding a child node (Node 1) to a treeview and then I want to add a Child Node (Node 2) to the newly added child node (Node 1):
VB Code:
AddChild(Selectednode, "John Doe", 12) 'Adding Node1
intNodeNum = TreeView1.Nodes(0).Nodes.Count + 1 ' I am attempting to get the
' index of last added node
Selectednode = TreeView1.Nodes(0).Nodes(intNodeNum) ' <== I get an error on this line
AddChild(Selectednode, "Address", 13) ' <==Node 2
How do I do this?
Hi Mark,
Why you want to do it by code?
If you go via TOOLBOX -> select TREEVIEW and create it on your Form,
then go to the properties of your TREEVIEW and select NODES and you can
Add Root and Add Cilds as many as you need.
Happy New Year,
sparrow1
-
Jan 1st, 2006, 05:13 AM
#4
Thread Starter
Giants World Champs!!!!
Re: Adding a Node to a Child Node - How?
 Originally Posted by sparrow1
Hi Mark,
Why you want to do it by code?
If you go via TOOLBOX -> select TREEVIEW and create it on your Form,
then go to the properties of your TREEVIEW and select NODES and you can
Add Root and Add Cilds as many as you need.
Happy New Year,
sparrow1
Happy New Year to you!!!
I want to be able to add the nodes during run time, specificaly when a User adds a name to a particular node (Node 1) I want to automatically add a child node to the newly created node (Node 2).
Thanks!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 1st, 2006, 05:32 AM
#5
Re: Adding a Node to a Child Node - How?
I thought so after I saw your second thread about Treeviews.
I'll try it.
Wkr,
sparrow1
-
Jan 1st, 2006, 06:23 AM
#6
Thread Starter
Giants World Champs!!!!
Re: Adding a Node to a Child Node - How?
 Originally Posted by sparrow1
I thought so after I saw your second thread about Treeviews.
I'll try it.
Wkr,
sparrow1
Thanks
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 1st, 2006, 11:40 AM
#7
Re: Adding a Node to a Child Node - How?
Why don't you have the AddChild method return a reference to the newly added node? That way you can simply pass that reference as the first argument to the next call to AddChild.
As to your error, the index of the last node is Count-1, not Count+1.
-
Jan 1st, 2006, 02:45 PM
#8
Thread Starter
Giants World Champs!!!!
Re: Adding a Node to a Child Node - How?
 Originally Posted by jmcilhinney
Why don't you have the AddChild method return a reference to the newly added node? That way you can simply pass that reference as the first argument to the next call to AddChild.
As to your error, the index of the last node is Count-1, not Count+1.
Thanks for the post. The following code is my AddChild Sub:
VB Code:
Private Sub AddChild(ByVal CurrentNode As TreeNode, _
ByVal strText As String, ByVal intImage As Integer, _
Optional ByVal intSelectImage As Integer = 99999)
Dim tvwnode As New TreeNode
With tvwnode
.Text = strText
.ImageIndex = intImage
If intSelectImage <> 99999 Then .SelectedImageIndex = intSelectImage Else .SelectedImageIndex = intImage
End With
CurrentNode.Nodes.Add(tvwnode)
TreeView1.ExpandAll()
End Sub
How would I alter this sub in order to return a reference to the newly added node?
Thanks!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 1st, 2006, 02:56 PM
#9
Fanatic Member
Re: Adding a Node to a Child Node - How?
VB Code:
Private [b]Function[/b] AddChild(ByVal CurrentNode As TreeNode, _
ByVal strText As String, ByVal intImage As Integer, _
Optional ByVal intSelectImage As Integer = 99999) [b]As TreeNode[/b]
Dim tvwnode As New TreeNode
With tvwnode
.Text = strText
.ImageIndex = intImage
If intSelectImage <> 99999 Then .SelectedImageIndex = intSelectImage Else .SelectedImageIndex = intImage
End With
CurrentNode.Nodes.Add(tvwnode)
'personally I would put this outside of this function
'[b]TreeView1.ExpandAll()[/b]
'return value
Return tvwnode
End Sub
Make a function out of it.
"so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman
-
Jan 1st, 2006, 08:11 PM
#10
Thread Starter
Giants World Champs!!!!
Re: Adding a Node to a Child Node - How?
Thanks, it worked like a charm!!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|