drag drop between two treeview

4 posts, 0 answers
  1. Jose Antonio
    Jose Antonio avatar
    3 posts
    Member since:
    Sep 2014

    Posted 22 Jan 2015 Link to this post

    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

  2. Milena
    Admin
    Milena avatar
    204 posts

    Posted 23 Jan 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jose Antonio
    Jose Antonio avatar
    3 posts
    Member since:
    Sep 2014

    Posted 27 Jan 2015 in reply to Milena Link to this post

    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.

  5. Milena
    Admin
    Milena avatar
    204 posts

    Posted 30 Jan 2015 Link to this post

    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.

     
Back to Top