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

Trouble copying items

5 Answers 74 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Magnus
Top achievements
Rank 1
Magnus asked on 22 Aug 2017, 12:43 PM

Hi! I'm using the implementation from the RowReorder-demo to get drag-n-drop in my RadGridView. It works really good, but I have an issue with copying. When reaching OnDrop the e.Effects are ALWAYS DragDropEffects.All (even when just moving an item).

In OnGiveFeedback the e.Effects is DragDropEffects.Copy (if pressing Ctrl), but it's not in OnDrop. I also checked the OnPreviewDrop method, but it's DragDropEffects.All there also.

Do I have to add something somewhere? In OnDragInitialize the e.AllowedEffects are set to DragDropEffects.All.

5 Answers, 1 is accepted

Sort by
0
Magnus
Top achievements
Rank 1
answered on 23 Aug 2017, 07:24 AM

I looked in the source code and found this in the class DragOperation:

 

private void OnDrop(DependencyObject source)
{
  this.lastDragEventArgs.UpdateAllowedEffects(this.allowedEffects);
  this.lastDragEventArgs.Effects = this.allowedEffects;
  object data = this.lastDragEventArgs.Data;
  if (source != null)
    this.RaiseDragEvent(DragDropManager.DropEvent, source);
  this.lastDragOverElement = (DependencyObject) null;
  this.RaiseDragDropCompleted(this.allowedEffects, data);
}

 

Should this.lastDragEventArgs.Effects really be set to this.allowedEffects? Shouldn't it be set to the current effects? (like move or copy) I don't claim to get all of the code but it might work just skipping that line of code? Since the EventArgs are reused it should already have the correct values.

0
Martin Ivanov
Telerik team
answered on 25 Aug 2017, 09:47 AM
Hello Magnus

Note that the effects of the drag/drop operation are valid only in the context of the element on which the drag/drop is currently executing. For example, if you start a drag operation for a GridViewRow and set the e.Effects in its OnGiveFeedback event handler, when you drag over another GridViewRow its effects will be different (the default ones). In order to update the effects for the drop target you can subscribe to its GiveFeedback event and set the effects there.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Magnus
Top achievements
Rank 1
answered on 25 Aug 2017, 12:32 PM

I don't set the Effects in OnGiveFeedback, I set the e.AllowedEffects in OnDragInitialize, and then use e.Effects in OnDrop. My code is almost identical to the code in the RowReorder-demo, so what's missing from that demo in order to Copy to work?

0
Accepted
Martin Ivanov
Telerik team
answered on 30 Aug 2017, 09:28 AM
Hello Magnus,

I tested this with the Effects on DragInitialize then OnDrop uses the proper effects. Maybe I am missing something. However, I isolated the Reorder Rows example and included a copy functionality on Ctrl click. Can you try it on your side and let me know if it helps?

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Magnus
Top achievements
Rank 1
answered on 30 Aug 2017, 09:49 AM

Thanks for your help. I misunderstood the RowReorder-demo. Since the application responds to Ctrl being pressed (showing a + sign) and the e.Effects in OnGiveFeeback was Copy I was under the impression that the demo was able to handle copying. My bad. Thanks for your time.

Tags
DragAndDrop
Asked by
Magnus
Top achievements
Rank 1
Answers by
Magnus
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or