Hi,
I have bound a ObservableCollection Hierarchical Nodes(with children collections ObservableCollection ) to the Items source of a TreeView Control.
I now want to add a new node as a child to the treeView in code behind, but I get told that the its Read Only,
Is there a way I can do this ?
Marcus
9 Answers, 1 is accepted
You need to modify the underlying collection. The changes to the collection will be reflected to the treeview.
You can check this help article for reference:
http://www.telerik.com/help/silverlight/radtreeview-populating-with-data-data-binding-to-object.html
Best wishes,
Valentin.Stoychev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thanks for the quick response.
What i am trying to do is add a new node like windows explorer i.e create a "new folder" child node and have it in editmode so the user can name it.
I guess i can add it to the underline collection then tree walk to find it it then set it in edit mode. is there a better way to do this common use case, seems a pain espically when you also have a service in the back end as well to call the node add as well.
Marcus
If you set a property in your business object that "tells" the TreeViewItem that it should be in edit mode this will be done automatically. We have a feature implemented in our controls called container bindings.
Here is how to use the container bindings:
1. Define the bindings to your bussines object:
<telerik:ContainerBindingCollection x:Key="containerBindings">
<telerik:ContainerBinding PropertyName="IsInEditMode" Binding="{Binding MyIsInEditModeBusinessProperty}" />
</telerik:ContainerBindingCollection>
2. Declare the bindings for the data template:
<DataTemplate x:Key="MyTemplate" telerik:ContainerBinding.ContainerBindings="{StaticResource containerBindings}" >
<TextBlock Text="{Binding}"/>
</DataTemplate>
Then ofcourse set the DataTemplate as an ItemTemplate. What the container bindings will do is they will bind a property from the RadTreeViewItem ( the container) to a property of your bussinse object.
Please let us know how it goes and if you have any other questions.
Sincerely yours,
Valentin.Stoychev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thanks again for the reply,
This does seem long winded ..
Finding your node in your Hierarchical ObservableCollection can take a while as well.
It would seem that the Tree and its items are the prefect why to add nodes and delete nodes as they are in the right struture and have the right methods etc.
Where as my ObservableCollection does not …
Marcus
If you still haven't found a solution to you problem, I have attached a sample project that demonstrates the scenario you are trying to achieve. Have a look at it and let me know if you find something unclear. I'd be glad to explain further.
@Henrik
I think you have picked the most correct approach for the scenario you are describing. There is no way to escape using separate templates and template selectors for this particular case. However, I'd be glad if you find an alternative and more elegant way to share it with us. Also, in what way do you expect RadTreeView to improve so that it provides better support for your scenario?
Let me know if you have additional questions or comments.
Sincerely yours,
Kiril Stanoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Now, for accessibility purposes I have found that the clearest, most intuitive way to let users add new nodes to a tree structure is to use the exact same UI paradigm as above, except that you now need one button for each level in the tree. This becomes a problem, because now you cannot just add a button, you will instead have to start mucking about with adding fake objects to your data collection instead of just creating GUI. Just like Marcus says, my list of business entities is not the place where I want to insert a "create node" button. That should live outside the data collection, and only when the button is clicked should the collection be affected.
I think if Telerik could provide some sort of way of inserting content before or after each level of nodes, the above scenario could be quite easily solved. It would also enable us to put in things like help texts at the top of a list of nodes. Of course, I do not know enough about the inner workings of RadTreeView to know whether this is possible to do.
I put together a little demo screen describing the two scenarios. I hope this makes my request a little clearer.
Thank you for clarifying your request. The idea is really good and I'll pass it to the people dealing with the treeview. When they get back at me, I'll let you know if this functionality can and will be supported out of the box. Meanwhile, if you have additional questions, let me know. I have also added 500 Telerik points to your account.
Kind regards,
Kiril Stanoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.