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

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

1 Answer 69 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 19 May 2011, 04:35 PM
Hello,

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?

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 24 May 2011, 03:01 PM
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
Tags
TreeView
Asked by
Rob
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or