ReadOnly Problems

10 posts, 0 answers
  1. Marcus Lambert
    Marcus Lambert avatar
    41 posts
    Member since:
    Aug 2009

    Posted 02 Dec 2009 Link to this post

    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

  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 02 Dec 2009 Link to this post

    Hello Marcus Lambert,

    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.
  3. DevCraft banner
  4. Marcus Lambert
    Marcus Lambert avatar
    41 posts
    Member since:
    Aug 2009

    Posted 02 Dec 2009 Link to this post

    Hi, Valentin
    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
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 02 Dec 2009 Link to this post

    Hi Marcus Lambert,

    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.
  6. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 02 Dec 2009 Link to this post

    I also would like a cleaner solution to this scenario. My situation is quite similar to Marcus. I need an extra node at the bottom of each child list. This node just contains an "Add folder" hyperlinkbutton.  There is a ridiculous amount of work involved just to just to get this simple thing working. I manually have to walk through the hierarchical collection of objects, add a "fake" node to each child collection, create separate data templates and code so that the node will switch to the correct the data template if it happens to be an "add folder" node. And then I have to clear these fake objects from the collection again before submitting it to the server. As Marcus mentions, this has to be a very common scenario. It would be great if Telerik could do something to alleviate the pain here...
  7. Marcus Lambert
    Marcus Lambert avatar
    41 posts
    Member since:
    Aug 2009

    Posted 02 Dec 2009 Link to this post

    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

  8. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 07 Dec 2009 Link to this post

    Hello 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.
  9. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 07 Dec 2009 Link to this post

    I'll take RadGridView as an example. Let's say you have a data list of customers. Underneath that list you want a button that just adds a new data row to the grid and puts that row in edit mode so that you can create a new customer entry quickly and easily. This scenario is quite easy to build. Just put your button underneath your grid, hook up to the click event, add a new CustomerEntity or whatever you're binding to, and your (nearly) done. There is of course the "put in edit mode" problem left to solve, but you are more or less there.

    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.
  10. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 07 Dec 2009 Link to this post

    Hello Henrik,

    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.
  11. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 08 Dec 2009 Link to this post

    Excellent. Thanks for the points.
Back to Top
DevCraft banner