This is a migrated thread and some comments may be shown as answers.

How do you add a GrandChild node?

8 Answers 314 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Gary Robson
Top achievements
Rank 1
Gary Robson asked on 20 Aug 2009, 11:29 AM
I'm sure this is simple but it's got me foxed.
I want to add a child node to a child node.

I store the location I want to place the new node, in this case parent node 0 and child node 0

            If r("DocNode1") = 0 And r("DocNode2") = 0 Then

                tvDocs.Nodes(0).Nodes.Add((r("DocTitle"))) '<<< How do I add the GrandChild node ?

            End If

Thanks.

8 Answers, 1 is accepted

Sort by
0
Gary Robson
Top achievements
Rank 1
answered on 20 Aug 2009, 12:11 PM
Isn't it just typical, after you search for hours for an answer, then go to the trouble to ask for help, five minutes later your crack it.

tvDocs.Nodes(0).Nodes(0).Nodes.Add((r("DocTitle")))
0
Victor
Telerik team
answered on 20 Aug 2009, 02:09 PM
Hello Gary Robson,

Thank you for sharing with the community your solution and do not hesitate to write in our forums if you encounter something else.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
H Vi
Top achievements
Rank 1
answered on 09 Mar 2010, 08:48 AM
Good afternoon,

I am currently facing the exact same problem as Gary Robson, however, I am under these conditions/restraints;
>>I do not know how many 'grandparent' does the node has. Meaning... it could be something like;

-Node1
|--Node2
|----Node3
|--Node4
|----Node5
|----Node6
|------Node7

In this case, for example, if I am at Node7, my parent is Node6, grandparent is Node4 and great-grandparent is Node1.
Assuming I do not know about grandparent Node4 and great-grandparent Node1...
Am I still able to add? My 'expected' result is;

-Node1
|--Node2
|----Node3
|--Node4
|----Node5
|----Node6
|------Node7
|--------[Node8]
Node 8, to be added.

I have tried using 'Insert', but it would put Node8 at the same level as its parent, Node7, giving me this;
-Node1
|--Node2
|----Node3
|--Node4
|----Node5
|----Node6
|------Node7
|------[Node8]
Ranking Node8 and Node7 to be sibling-level, and not parent-child.

I appreciate all help given.
Thanks and yours sincerely,
H. Vi
0
Victor
Telerik team
answered on 09 Mar 2010, 10:10 AM
Hello H Vi,

Thank you for contacting us. You simply need to add Node8 to the Nodes collection of Node7.

Best wishes,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
H Vi
Top achievements
Rank 1
answered on 09 Mar 2010, 10:22 AM
Good evening Victor,
Thank you for your prompt reply!

I would like to add that umm, Node8 -and- Node7 are all created during runtime.

I am unable to find a 'collection' to add. I am sorry if this sounds confusing. Currently, I 'insert' nodes like this;
radTreeView1.Nodes.Insert (parIDInTree + 1, newNode);
*parIDInTree is the Parent Node's ID in the Tree Form. This of course, doesn't work, since the added node becomes a 'sibling' node.

I also tried;
radTreeView1.Nodes[parentName].Nodes.Add(newNode);
*Where... in a self explanatory manner, I try to add the node under its parent's name. However, as there are 'grandparents', this is not feasible either.

I have no idea where to 'plug in' the Collections keyword.

Sorry for all the trouble, and a sincere thanks for the prompt reply~
Yours sincerely,
H. Vi

0
Victor
Telerik team
answered on 10 Mar 2010, 10:03 AM
Hello H Vi,

If you know the name of the parent node to which you to add the child node, you can find it by using RadTreeView command mechanism and FindByTextCommand in particular. You can first use the command to get a reference to the parent and then add the child node to the parent Nodes collection. Here is an example:

FindByTextCommand cmd = new FindByTextCommand();
object parent = RadTreeView.ExecuteScalarCommand(yourTreeView.Nodes, -1, cmd, "Node8");
if(parent != null)
{
    (parent as RadTreeNode).Nodes.Add(childNode);
}

Write again if you need further assistance.

All the best,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
H Vi
Top achievements
Rank 1
answered on 11 Mar 2010, 02:12 AM
Good morning Victor,

Thanks sincerely for the code snippet! This is exactly what I am looking for!

I too, have learnt something new. Thank you so much for your help and advice.

Yours sincerely,
H. Vi
0
Victor
Telerik team
answered on 11 Mar 2010, 08:59 AM
Hello H Vi,

Thank you, I am glad to be of help.

Sincerely yours,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Treeview
Asked by
Gary Robson
Top achievements
Rank 1
Answers by
Gary Robson
Top achievements
Rank 1
Victor
Telerik team
H Vi
Top achievements
Rank 1
Share this question
or