How to use DragDropManager with AllowDrop

3 posts, 0 answers
  1. Alfons
    Alfons avatar
    14 posts
    Member since:
    Mar 2012

    Posted 23 Aug 2012 Link to this post

    Hi,

    I am using the DragDropManager and I managed to get it working. Actually it is working too good. I set AllowDrop = true on only 2 controls, but I can drop the object on all controls.

    1. I had hoped to get a Cursors.No on areas where AllowDrop wasn't set to true. How can I do that? Even better would be not to fire the OnDrop() event in this case.
    2. If I always have to handle the OnDrop event: Is there a way I can find out in the OnDrop() and OnDragCompleted() method to see if the Drop was legitimate/successful or not?

    Regards,

    Alfons
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 24 Aug 2012 Link to this post

    Hello,

    The AllowDrop is inherited property so if you set it to true on a Grid for example, everything you put in that Grid will have AllowDrop = True. To workaround this just set it to false wherever you need. If it is set to false and you try to drop the dragged item there, the OnDrop event will not be fired.

    If this is not the case please send us a sample project illustrating the issue.

    Greetings,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Alfons
    Alfons avatar
    14 posts
    Member since:
    Mar 2012

    Posted 29 Aug 2012 Link to this post

    Hi Rosen,

    I guess I was mistaken. As you said, the AllowDrop does work. To change the cursor I used the following code:

    void OnDragOver(object sender, DragEventArgs args)
    {
        var ctrl = sender as Control;
        if (ctrl != null && ctrl.AllowDrop)
        {
            args.Effects = DragDropEffects.Move;
        }
        else
        {
            args.Effects = DragDropEffects.None;
        }
    }
     
    private void OnGiveFeedback(object sender, GiveFeedbackEventArgs args)
    {
        if (args.Effects == DragDropEffects.Move)
        {
            args.UseDefaultCursors = false;
            args.SetCursor(Cursors.Hand);
        }
        else if (args.Effects == DragDropEffects.None)
        {
            args.UseDefaultCursors = false;
            args.SetCursor(Cursors.No);
        }
        else
        {
            args.UseDefaultCursors = true;
        }
     
        args.Handled = true;
    }
Back to Top