Drag 'n' Drop - How to update data object?

2 posts, 0 answers
  1. Rob
    Rob avatar
    238 posts
    Member since:
    Jan 2009

    Posted 19 May 2011 Link to this post


    I'm working with drag and drop inside a RadTreeView control...  My data objects are pretty simple:

    class TreeNode
        int ID,
        string Header,
        ObservableCollection<TreeNode> Children,
        TreeNode Parent,    

    Drag and Drop seems to work well out of the box and updates my children collection appropriately as i move items around...  my question is... what is the best way to update the "Parent" property of a TreeNode after I have moved it.  Is there a way to build my dataobject so this is done automatically?  or do i have to manually do it in one of the drag completed events?
  2. Petar Mladenov
    Petar Mladenov avatar
    3151 posts

    Posted 24 May 2011 Link to this post

    Hello Rob,

    Suppose we have a RadTreeView consisting of Teams and Players hierarchy. If you move a player from one team to another, you can update your parent or parentId like so:
    public Team()
               this.Players = new ObservableCollection<Player>();
               this.Players.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Players_CollectionChanged);
           void Players_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
               if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                   Player movedPlayer = (sender as ObservableCollection<Player>)[0] as Player;
                   movedPlayer.parentTeam = this;
    The CollectionChanged event of the Players collection will fire with every drag and drop operation that moves a player from one team to another.
    Please let us know if this approach satisfies you.

    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
Back to Top