Cancel drop after drop complete

9 posts, 1 answers
  1. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 29 Sep 2010 Link to this post

    Hello,

    I am creating an application that will bring up a messagebox after an item has been dragged and dropped from one treeview to another.  I would like the messagebox to prompt the user with a Yes/No after the drop is complete on the second treeview.  If the user selects no, the drop can then be canceled.

    Thanks
    Ryan

    RadDragAndDropManager.AddDropInfoHandler(this.CreatedStepItems, new EventHandler<DragDropEventArgs>(this.CreatedStepItems_OnDropInfo));
     
     private void CreatedStepItems_OnDropInfo(object sender, DragDropEventArgs e)
            {
                if (e.Options.Status == DragStatus.DropComplete)
                {
                     
                    var t = MessageBox.Show("Cancel", "Cancel", MessageBoxButton.YesNo);
                    if (t == MessageBoxResult.Yes)
                        //Cancel
                    else
                        //Dont
                }
            }
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 29 Sep 2010 Link to this post

    Hi Ryan Black,

    The RadTreeView has a DragAndDrop feature implemented. You can find more info here.

    So, instead of adding RadDragAndDropManager handlers, you can handle the second RadTreeView PreviewDragEnded() event. For example like so:
    private void treeView1_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
    {
        MessageBoxResult result =  MessageBox.Show("Would you like to cancel the drag operation?","Confirmation",MessageBoxButton.OKCancel);
        if (result == MessageBoxResult.Cancel)
            e.Handled = true;
    }


    Kind regards,
    Tina Stancheva
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 29 Sep 2010 Link to this post

    That works, but now the item is not on in the left treeview or the right.
  5. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 01 Oct 2010 Link to this post

    Hi Ryan Black,

    I prepared a project illustrating the functionality you need. Please take a look at it and tell me if it solves your problem.

    Do not hesitate to ask if you need further assistance.

    Greetings,
    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
  6. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 04 Oct 2010 Link to this post

    Perfect example and just what I was looking for.

    Thanks so much!
    Ryan
  7. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 04 Oct 2010 Link to this post

    Petar,

    After looking more closely at the example, I noticed that the left treeview loses the item once the drop is confirmed.  How would I be able to "copy" from the left list to the right using the provided example?

    Thanks
    Ryan
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Oct 2010 Link to this post

    Hello Ryan Black,

    We modified the previous solution you received so that you are able to copy the RadTreeViewItems from one tree to the other and to itself. In addition,  the boolean property dropping from the previous example is no more necessary.

    Please take a look at the attached solution and tell us if it helps you. Feel free to ask if you need more info.

    Greetings,
    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
  9. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 07 Oct 2010 Link to this post

    Petar,

    I should have been a little more clear in my sample requirement but didn't think it would matter.  In my actual project the second treeview can be empty and the user can drag items from the left treeview to the right.  The same item from the left can be dragged over to the right more than once.  In the example that we are working with, if you have the second treeview be blank, the code with e.TargetDropItem becomes null and does not work correctly.

    Could you please update the sample to reflect the second treeview starting out having no items?

    Thanks again for all your help!
    Ryan
  10. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 11 Oct 2010 Link to this post

    Hello Ryan Black,

    I modified the solution in order to allow adding items into the empty right tree.

    Please note that handling the PreviewDragEnded event cancels the default  RadTreeView drag/drop logic. This means that you have to implement your own custom logic to cover cases like dropping an item to an empty tree or dropping items before or after a particular item. 
     
    I hope the attached project  satisfies your needs. Please tell me if you need further assistance.  

    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
UI for WPF is Visual Studio 2017 Ready