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

Drag & Drop between treeviews

3 Answers 107 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
pirobox
Top achievements
Rank 1
pirobox asked on 17 Mar 2010, 11:42 AM
Hi,
i'm trying to use the drag&drop feature between two treeviews. Everything works, but I'm not able to customize it to address my business layer scenario.
By the end the problem is that the moved nodes are automatically reflected in the underlining collections: the source nodes are removed from the source collection and added to the target source. Is there a way to stop it? For example I would like to leave the dragged node in the source collection.

Best regards, Andrea Pirola

3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 17 Mar 2010, 03:21 PM
Hi Andrea,

This can be achieved by handling the PreviewDragEnded event of the source treeview (the one you are dragging from).

public MainPage()
{
    InitializeComponent();
 
    this.treeView1.ItemsSource = new DataItems();
    this.treeView2.ItemsSource = new ObservableCollection<DataItem>();
 
    treeView1.PreviewDragEnded += new Telerik.Windows.Controls.RadTreeViewDragEndedEventHandler(treeView1_PreviewDragEnded);
}
 
void treeView1_PreviewDragEnded(object sender, Telerik.Windows.Controls.RadTreeViewDragEndedEventArgs e)
{
e.Handled = true;
}

Please find attached a sample demonstrating this functionality.
However, if you want to drag back, you will need to clone the item and add it manually.
Let us know if you have additional questions or comments on the topic.

Kind regards,
Kiril Stanoev
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.
0
Luis Patroni
Top achievements
Rank 1
answered on 09 Jul 2010, 02:51 PM
Hi, I want to drop the same item to another treeview many times, im doing a clone but it's not working very well, could you help me ?
In this example I drag items the from RadTreeView1 to RadTreeview2
//RadTreeView1
        private void RadTreeView1_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
        {
            e.Handled = true;
        }
 
//DropInfo of RadTreeView2
  private void OnDropInfo(object sender, DragDropEventArgs e)
        {
          ICollection draggedItems = e.Options.Payload as ICollection;
           if (e.Options.Status == DragStatus.DropComplete)
           {
                ass = draggedItems.Cast<Benner.Sc.Questionario.ClassesTreeView.Assunto>());
                RadTreeViewItem destItem = e.Options.Destination as RadTreeViewItem;
                //here I clone the item that I want to send..
                Benner.Sc.Questionario.ClassesTreeView.Assunto assunto = ass.First().CloneAssunto(ass.First());
                destItem.Items.Add(assunto); //add cloned item to RadTreeView2
            }
        }



0
Kiril Stanoev
Telerik team
answered on 14 Jul 2010, 01:28 PM
Hi Luis,

I modified the previous example to demonstrate this functionality. Please take a look at the attached project and let me know if it helps.

Greetings,
Kiril Stanoev
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
pirobox
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Luis Patroni
Top achievements
Rank 1
Share this question
or