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

12 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
    1240 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. 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?
  4. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1240 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 >>
  5. 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();
    }
  6. santosh
    santosh avatar
    6 posts
    Member since:
    Dec 2017

    Posted 13 Dec 2017 in reply to Anders Link to this post

    I am trying to update drag preview icon as cross in case target item is null. This scenario comes when treeveiw item is dragged outside treeitem in same treeview area.

     

    if (options.DropTargetItem == null)
                {
                     options.DropAction = DropAction.None;            
                options.UpdateDragVisual();
                }

     

    but drag preview still coming and it shows preview text as after root item.

     

    Can you please help addressing this bug

  7. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1594 posts

    Posted 18 Dec 2017 Link to this post

    Hello Santosh,

    Can you share some runnable code showing the issue on your side? This will help me in better understanding your scenario.

    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.
  8. santosh
    santosh avatar
    6 posts
    Member since:
    Dec 2017

    Posted 27 Dec 2017 in reply to Martin Ivanov Link to this post

    I have attached screen shots and sample app.
  9. santosh
    santosh avatar
    6 posts
    Member since:
    Dec 2017

    Posted 27 Dec 2017 in reply to santosh Link to this post

    I have attached screen shots and sample app.
  10. santosh
    santosh avatar
    6 posts
    Member since:
    Dec 2017

    Posted 27 Dec 2017 in reply to santosh Link to this post

    sample app can be found from below link

     

    https://www.telerik.com/forums/radtreeview---amend-drop-preview-line#VMjF7lbxPUKxzn0MhCNkGQ

  11. santosh
    santosh avatar
    6 posts
    Member since:
    Dec 2017

    Posted 27 Dec 2017 in reply to santosh Link to this post

    Sample project taken from belwo link

    https://www.telerik.com/forums/radtreeview---amend-drop-preview-line#VMjF7lbxPUKxzn0MhCNkGQ

  12. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    138 posts

    Posted 29 Dec 2017 Link to this post

    Hello,

    Thank you for the attached resources.

    I am attaching a modified version of the project from the referenced topic. Please notice that when you try to drop a treeview item somewhere in the window, the drag visual is updated as expected. May I ask you to see how this project differs from the setup at your end. Additionally if you want to disable the drag and drop preview line, you can set the IsDropPreviewLineEnabled property of the RadTreeView to False.

    Regards,
    Vladimir Stoyanov
    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.
Back to Top