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
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
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 >>
Any suggestions on what to try?
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();
}
}
Regards,
Pavel R. Pavlov
Telerik
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 >>
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();
}
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
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
sample app can be found from below link
https://www.telerik.com/forums/radtreeview---amend-drop-preview-line#VMjF7lbxPUKxzn0MhCNkGQ
Sample project taken from belwo link
https://www.telerik.com/forums/radtreeview---amend-drop-preview-line#VMjF7lbxPUKxzn0MhCNkGQ
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