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
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
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
Thanks so much!
Ryan
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
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.
Petar Mladenov
the Telerik team
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
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.
Petar Mladenov
the Telerik team