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
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.
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
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?
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
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.