Trouble copying items

6 posts, 1 answers
  1. Magnus
    Magnus avatar
    23 posts
    Member since:
    Dec 2011

    Posted 22 Aug Link to this post

    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.

  2. Magnus
    Magnus avatar
    23 posts
    Member since:
    Dec 2011

    Posted 23 Aug Link to this post

    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.

  3. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1408 posts

    Posted 25 Aug Link to this post

    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.
  4. Magnus
    Magnus avatar
    23 posts
    Member since:
    Dec 2011

    Posted 25 Aug in reply to Martin Ivanov Link to this post

    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?

  5. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    1408 posts

    Posted 30 Aug Link to this post

    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.
  6. Magnus
    Magnus avatar
    23 posts
    Member since:
    Dec 2011

    Posted 30 Aug in reply to Martin Ivanov Link to this post

    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.

Back to Top