This is a migrated thread and some comments may be shown as answers.

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

11 Answers 165 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 07 Aug 2013, 08:37 AM
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;
        }

11 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 11 Aug 2013, 08:25 AM
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 >>
0
Anders
Top achievements
Rank 1
answered on 12 Aug 2013, 09:39 AM
Yes, I'm doing that. Subscribing with (...,true) , my code is executed and it has no effect.

Any suggestions on what to try?
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 14 Aug 2013, 01:21 PM
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 >>
0
Anders
Top achievements
Rank 1
answered on 16 Aug 2013, 06:31 AM
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();
}
0
santosh
Top achievements
Rank 1
answered on 13 Dec 2017, 10:07 AM

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

0
Martin Ivanov
Telerik team
answered on 18 Dec 2017, 09:22 AM
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.
0
santosh
Top achievements
Rank 1
answered on 27 Dec 2017, 12:50 PM
I have attached screen shots and sample app.
0
santosh
Top achievements
Rank 1
answered on 27 Dec 2017, 12:54 PM
I have attached screen shots and sample app.
0
santosh
Top achievements
Rank 1
answered on 27 Dec 2017, 12:59 PM

sample app can be found from below link

 

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

0
santosh
Top achievements
Rank 1
answered on 27 Dec 2017, 12:59 PM

Sample project taken from belwo link

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

0
Vladimir Stoyanov
Telerik team
answered on 29 Dec 2017, 03:20 PM
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.
Tags
TreeView
Asked by
Anders
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Anders
Top achievements
Rank 1
santosh
Top achievements
Rank 1
Martin Ivanov
Telerik team
Vladimir Stoyanov
Telerik team
Share this question
or