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
10 Answers, 1 is accepted
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.
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
;
}
Can you tell me what you mean by arrow cue? Is this the mouse cursor? Or the drag visual element? Or the small icon next to the cursor that shows the allowed drag/drop operation?
To change the mouse cursors while dragging you can subscribe to the DragInitialize or GiveFeedback events of the DragDropManager and set the Cursor property of the dragged element or use the SetCursor method of the GiveFeedbackEventArgs class. Here is an example for the both approaches:
private
void
OnElementGiveFeedback(
object
sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e)
{
e.SetCursor(Cursors.Arrow);
}
private
void
OnElementDragInitialize(
object
sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
var element = (FrameworkElement)sender;
element.Cursor = Cursors.Arrow;
}
To change the drag visual you can set the DragVisual property of the DragInitializeEventArgs class.
private
void
OnElementDragInitialize(
object
sender, DragInitializeEventArgs e)
{
e.DragVisual = myArrowShapeControl;
}
To change the allowed effects icon you can set the AllowedEffects property of the DragInitializeEventArgs class.
private
void
OnElementDragInitialize(
object
sender, DragInitializeEventArgs e)
{
e.AllowedEffects = DragDropEffects.Copy;
}
Regards,
Martin Ivanov
Progress Telerik
Hi,
We have previously working functionality, where we drag from treeview and drop into schedular where we have use RadDragansDropmanager for create arrow using RadDragAndDropManager.GenerateArrowCue() which point from source to destination
But as we upgrade into latest WPF telerik version we lost that functionality.
Now, We able to get same effect when we use RadDragAndDropManager.ExecutionMode = DragExecutionMode.Legacy but the schedular not able to recognize external source item.
We have use custom dragbehiviour for schedular to save and delete data by inheriting from ScheduleViewDragDropBehavior class.Which stop working when we used " DragExecutionMode.Legacy" setting for treeview
We are seeking help on how we can able to achieve the same
The new DragDropManager doesn't support the arrow cue feature. To achieve your requirement you can implement a custom drag visual and render the arrow shape manually on mouse move. Alternatively, you can define a panel above the controls that will drag/drop items and add a custom arrow shape in it. Then on drag/drop manually update the shape.
I hope that helps.
Regards,
Martin Ivanov
Progress Telerik
I prepared a small example that shows a possible approach that you can try. I hope it helps.
Regards,
Martin Ivanov
Progress Telerik
Hi Martin ,
Thanks for the reply
We have try to implement same into our project. In our case we drag item from Tree view and drop to the Radschedular control. Using your suggestion we able to get the custom arrow as required but when we drop the same at schedular it not able to recognize the same.
We have implemented CustomScheduleViewDragDropBehavior which is inherit from ScheduleViewDragDropBehavior.
If we use the DragDropManager.AddDragInitializeHandler, DragDropManager.AddDragOverHandler and DragDropManager.AddDragDropCompletedHandler handler over the treeView, Schedular Drop functionality stop working.
I am afraid that without your implementation I cannot tell what is going on. Can you prepare some runnable code and post it here? Or open a new support ticket from your telerik.com account and share a runnable project there.
Regards,
Martin Ivanov
Progress Telerik