add new item when there is already childrens

11 posts, 0 answers
  1. Michal Revivo
    Michal Revivo avatar
    22 posts
    Member since:
    Mar 2009

    Posted 02 Aug 2008 Link to this post

    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
  2. Valio
    Valio avatar
    102 posts
    Member since:
    Jun 2006

    Posted 03 Aug 2008 Link to this post

    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
  3. DevCraft banner
  4. Michal Revivo
    Michal Revivo avatar
    22 posts
    Member since:
    Mar 2009

    Posted 10 Aug 2008 Link to this post

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

    Posted 11 Aug 2008 Link to this post

    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.
  6. Michal Revivo
    Michal Revivo avatar
    22 posts
    Member since:
    Mar 2009

    Posted 14 Aug 2008 Link to this post

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

    Posted 14 Aug 2008 Link to this post

    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.
  8. Michal Revivo
    Michal Revivo avatar
    22 posts
    Member since:
    Mar 2009

    Posted 29 Aug 2008 Link to this post

    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
  9. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 29 Aug 2008 Link to this post

    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.
  10. Angeli
    Angeli avatar
    29 posts
    Member since:
    Apr 2011

    Posted 27 Jun 2011 Link to this post

    Hi. I'm having the same problem as this. How was this solved?
  11. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Jun 2011 Link to this post

    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
  12. Angeli
    Angeli avatar
    29 posts
    Member since:
    Apr 2011

    Posted 29 Jun 2011 Link to this post

    Hi Petar. I explained my scenario in another forum thread. Please check it out. Thanks~
Back to Top
DevCraft banner