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

add new item when there is already childrens

10 Answers 113 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michal Revivo
Top achievements
Rank 1
Michal Revivo asked on 02 Aug 2008, 08:14 PM
Hi

I successfully add new items and edit them.
But could you explain how I can add new item
for node which have already children ?

it seems that I can add only node which have not children ?

Thanks
Fred

10 Answers, 1 is accepted

Sort by
0
Valio
Top achievements
Rank 1
answered on 03 Aug 2008, 07:11 AM
Hi Fred,

There is no difference in the way you add new items to a given node.
Just use the Items collection and add the newly created nodes there.
RadTreeViewItem myNewItem = new RadTreeViewItem();  
myNewItem.Header = "NewlyCreated";  
myParent.Items.Add(myNewItem); 

An exception from this is when you have databinded the treeview via the ItemsSource property, but this does not seems to be your case.

Best regards,
Valentin.Stoychev
Telerik
0
Michal Revivo
Top achievements
Rank 1
answered on 10 Aug 2008, 06:46 PM
Thanks Valentin
But I didn't explain correctly my question.
I would like to add a new node in the TreeView not dynamically but via the GUI.
I add these 2 attributes to my RadTreeView
IsEditable="true" LoadOnDemand="radTreeView1_LoadOnDemand"
When i click on a node which have no childs then I new node is created
and I can edit it with F2 - perfect!!
But when there are childs it open all the childs ( like expand).
How I can add a new node in this case ?

Thanks
Fred
0
Valentin.Stoychev
Telerik team
answered on 11 Aug 2008, 08:22 AM
Hello Fred,

If I understand you correctly you are adding the new childs in this event handler:
"radTreeView1_LoadOnDemand". After that the LoadOnDemand event is not fired anymore because the node is already populated. If you need to add more childs to the same node you should attach to the RadTreeViewItem.Expanded event and add the childs in this event handler.

Let me know if this is working for you.

All the best,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Michal Revivo
Top achievements
Rank 1
answered on 14 Aug 2008, 01:36 PM
Hi
sorry, but could you produce a sample ?
i don't understand why I have to add childs in the expanded event.
sometimes I want to expand without add ...
regards
Fred
0
Valentin.Stoychev
Telerik team
answered on 14 Aug 2008, 05:22 PM
Hi Fred,

It seems like I do not understand completely you scenario. Basically you can add new items to any item at any time if you are not using data binding (which as I understand is your case).

Can you please clarify again what the exact problem is - when you are not able to add the new items?

Sorry that it takes so long to identify the problem. I hope that with the next iteration we will be able to help you solve the issue.

Kind regards,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Michal Revivo
Top achievements
Rank 1
answered on 29 Aug 2008, 05:17 AM
Hi Valentin

I am using Data Binding.
i try to clarify my problem:

For a node which have childs, how are you doing the difference
between expand the node or add a new child ?

In my sample code,
if the node has childs, clicking on will expand the node
if not will add a new one.

How i can add a new child for a node which have already childs ?

Is it more clear ?
Regards
Fred
0
Valentin.Stoychev
Telerik team
answered on 29 Aug 2008, 07:51 AM
Hello Fred,

First of all - since you are using DataBinding you should work entirely with the Collection to add/remove items from the TreeView. Also your Collection should be an ObservableCollection in order the changes in the collection to be reflected in the TreeView. Read more on the ObservableCollection and databinding to an ItemsControl (which the TreeView inherits from) here:
http://blogs.msdn.com/andybrit/archive/2008/03/05/1-22-2008-using-observablecollections-and-databinding-with-silverlight-2.aspx

Here is an answer to your questions:
For a node which have childs, how are you doing the difference
between expand the node or add a new child ?

You can see if the node has child Items by checking the count of the node Items collection.

Hope this is clear. If not - you can send as a simple project with comments and we will investigate it.

Thanks!

Kind regards,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Angeli
Top achievements
Rank 1
answered on 27 Jun 2011, 08:20 AM
Hi. I'm having the same problem as this. How was this solved?
0
Petar Mladenov
Telerik team
answered on 29 Jun 2011, 02:07 PM
Hello Angeli,

Could you please elaborate more on your scenario? How do you populate your tree and what exactly you are trying to achieve? You can also check  out our help articles and demos.

All the best,
Petar Mladenov
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
Angeli
Top achievements
Rank 1
answered on 29 Jun 2011, 03:10 PM
Hi Petar. I explained my scenario in another forum thread. Please check it out. Thanks~
Tags
TreeView
Asked by
Michal Revivo
Top achievements
Rank 1
Answers by
Valio
Top achievements
Rank 1
Michal Revivo
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Angeli
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or