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

drag drop between two treeview

3 Answers 201 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jose Antonio
Top achievements
Rank 1
Iron
Jose Antonio asked on 22 Jan 2015, 04:03 PM
Hi, sorry but my english is not well. I´m newby in development WPF app.

I have a problem with implement drag drop between two treeview and i need help.
That´s what i want to do:
  1. I have two treeview. First treeview has hierarchy like:

      A1
          A1.1
             A.1.1.1
          B1.2
             B.1.2.1
             B.1.2.2
                B.1.2.2.1
                B.1.2.2.2
             B.1.2.3
             ...
2. The other treeview is empty

Well, i like drag both elements as parents from treeview (1) to (2). 
The first requirement is that drag drop from 1 to 2 the elements from 1 are deleted and can drag parents complete with all its child
The second requirement is when drag from 2 to 1 can only be done on the parent element to which it belongs for example:
    Subitem B.1.2.2.2 can only drag about B.1.2.2
The third requirement is that within the tree two items can be sorted between them

Can I help me?, please

3 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 23 Jan 2015, 01:24 PM
Hi Jose,

You can take a look at our help topic "Implemenct Drag and Drop between TreeViews" and our SDK example. The demo demonstrates similar scenario with drag and drop between two RadTreeView controls with different view models, so you can give it a try. Then, you can customize further the drag and drop logic per your requirements using DragDropManager events.

I hope this online resources will get you started. Don't hesitate to write back if you have more questions.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jose Antonio
Top achievements
Rank 1
Iron
answered on 27 Jan 2015, 06:04 PM
Hi Milena,

Thanks for answer, i read the complete help topic and de sdk example and i keep busy.

My two radtreeview controls have same view models. My problem is when i drag the inferior level B.1.2.2.1 i would like to de second treeview show:
  B.1.2
      B.1.2.2
         B.1.2.2.1

If i drag other child (B.1.2.2.2) then the second treeview show:
  B.1.2
     B.1.2.2
         B.1.2.2.1
         B.1.2.2.2

If i drag entire parent B.1.2.2 the second treeview add only child  that not exist.

For last when i drag from second treeview to original treeview i can only drag into (in this example) B.1.2 parent.

Thanks for all.

0
Milena
Telerik team
answered on 30 Jan 2015, 12:54 PM
Hi Jose,

I will try to answer all of your questions in the order they appeared.

When you drag an item you can drop it undefined, before, after or inside another item. More about the customization of the DropPosition you can find in our help topic “Enable only drop inside” .

So, let say that you drop an item inside another item. If the target item has children (e.g. B 1.2) then the dragged item will go at the last position of this children collection. As far as I understand your scenario you need to customize this behavior and drop the item on a specific position. In this case you can use the Drop event and TreeViewDragDropOptions (an object that holds all information related to the drag, including a collections of DraggedItems). So your implementation could be something like this:

private void OnTreeDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
    var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
 
    var draggedCollection = options.DraggedItems;
 
    //custom logic
 
    targetItem.Items.Insert(positionIndex, sourceItem);
}

As a reference you can see the OnApplicationTreeDrop event in the DragDropBetweenTreeViews example where the TreeViewDragDropOptions is also used.

If i drag entire parent B.1.2.2 the second treeview add only child that not exist.
H
ere you can use a similar approach and check if some of the dragged items already exist in the target item, e.g. checking the titles (B 1.2) of the items or some other property of your viewmodel, and add only the items you need.

I hope this information will help you customize the drag and drop operation per your requirements.

Regards,

Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeView
Asked by
Jose Antonio
Top achievements
Rank 1
Iron
Answers by
Milena
Telerik team
Jose Antonio
Top achievements
Rank 1
Iron
Share this question
or