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

Cancel drop after drop complete

8 Answers 137 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ryan Black
Top achievements
Rank 1
Ryan Black asked on 29 Sep 2010, 04:29 PM
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
            }
        }

8 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 29 Sep 2010, 04:51 PM
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
0
Ryan Black
Top achievements
Rank 1
answered on 29 Sep 2010, 06:09 PM
That works, but now the item is not on in the left treeview or the right.
0
Accepted
Petar Mladenov
Telerik team
answered on 01 Oct 2010, 03:36 PM
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
0
Ryan Black
Top achievements
Rank 1
answered on 04 Oct 2010, 03:31 PM
Perfect example and just what I was looking for.

Thanks so much!
Ryan
0
Ryan Black
Top achievements
Rank 1
answered on 04 Oct 2010, 09:38 PM
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
0
Petar Mladenov
Telerik team
answered on 07 Oct 2010, 03:56 PM
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
0
Ryan Black
Top achievements
Rank 1
answered on 07 Oct 2010, 06:46 PM
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
0
Petar Mladenov
Telerik team
answered on 11 Oct 2010, 04:24 PM
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
Tags
TreeView
Asked by
Ryan Black
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Ryan Black
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or