During drag-and-drop -- how to let the treeview know that the in-progress-drag is not allowed?

5 posts, 1 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 07 Aug 2013 Link to this post

    Hi telerik,

    Currently I do as below, which I thought was the way to do it. It has no effect on drag-cursor. What is your recommendation?
    Thanks,

    Anders, Denmark
            public void OnDragOver(object sender, DragEventArgs args)
            {
    ...
                if ( [disallow drag] )
                {
                    args.Effects = DragDropEffects.None;
                }
                args.Handled = true;
            }
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 11 Aug 2013 Link to this post

    Hi Anders,

    You are right that this is the correct approach in your scenario. However, I am not sure about your implementation but you need to have in mind that you have to use the events of the DragDropManager (read more).

    Furthermore, you need to subscribe to the already handled events (with third parameter true) like this:

    DragDropManager.AddDragOverHandler(xTreeView, OnDragOver, true)

    Please give this approach a try and let me know if you need any further assistance.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 12 Aug 2013 Link to this post

    Yes, I'm doing that. Subscribing with (...,true) , my code is executed and it has no effect.

    Any suggestions on what to try?
  5. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 14 Aug 2013 Link to this post

    Hi Anders,

    A possible reason for the reported behavior is that the DragDropEffects.None is not included in the AllowedEffects. Please note that you are allowed to chose between the options that are present in the AllowedEffects property, only. If you choose not existing option, the UI will not respect that setting.

    Please note that the AllowedEffects can be set only in the DragInitialized handler. However, if you need to notify the user that a drop operation is not possible you can subscribe to the DragOver event of the RadTreeView control and access the TreeViewDragDropOptions. After that you will be able to check the DropPosition, DropTargetItem, DropTargetTree properties and based on them you can decide if the drop operation is allowed or not.

    In case that you want to restrict a drop operation you can set the DropAction property to None. This will prevent the drop operation. In order to update the drag visual you can call the UpdateDragVisual() method. By doing so the mouse cursor will be changed. You can use the following code:

    private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        if (options != null)
        {
            options.DropAction = DropAction.None;
            options.UpdateDragVisual();
        }
    }
    Please give this approach a try and let me know if it works for you.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 16 Aug 2013 Link to this post

    Thank you!

    That solved it for me.
    options.DropAction is set instead of args.Effects...


    //args.Effects = DragDropEffects.None;
    if (options != null)
    {
        options.DropAction = DropAction.None;
        options.UpdateDragVisual();
    }
Back to Top
UI for WPF is Visual Studio 2017 Ready