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

Disallow dropping on source

3 Answers 189 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Rico
Top achievements
Rank 1
Rico asked on 19 Jun 2018, 08:52 AM

I am using the telerik library with version 2017.3.1018.45.
At the moment I'm struggling with a drag & drop implementation between a RadGridView and RadTreeView. A row must be draggable from the RadGridView to the RadTreeView only.
The drag & drop from the grid to the tree works perfectly. Unfortunately it is also possible to drop elements from the grid on the grid itself. The Effects property of GiveFeedBackEventArgs in OnGiveFeedback() is Move when staying with the mouse over the grid. It should be None though.

Setting AllowDrop=false on the grid does not make a difference.
I as well tried to disallow dropping before the mouse pointer leaves the grid - using OnDragLeave - but it fires as well when the pointer still is over the grid.
Another approach is to compare the source and destination when dropping. It does not seem possible though to figure out the drop destination in the OnDrop or OnDragDropCompleted events.

How can I omit dropping a grid element on the same grid?

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 22 Jun 2018, 08:45 AM
Hello Rico,

I will get back to you with a suggestion in the next hour.

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
Martin Ivanov
Telerik team
answered on 22 Jun 2018, 09:13 AM
Hello Rico,

To achieve your requirement you can handle the PreviewDrop event. Here is an example in code:
DragDropManager.AddPreviewDropHandler(this.AssociatedObject, OnPreviewDrop);

private void OnPreviewDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
    var gridView = (RadGridView)sender;
    var dropTarget = e.OriginalSource as FrameworkElement;
    var dropTargetGrid = dropTarget.ParentOfType<RadGridView>();
    if (dropTargetGrid != null && dropTargetGrid == gridView)
    {
        e.Handled = true;
    }
}

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
Rico
Top achievements
Rank 1
answered on 22 Jun 2018, 12:31 PM

Thank you very much for your answer.

I work with the OnDragDropCompleted() function which needs to know whether the source equals the destination. Your code doesn't work in that function. But thanks to your answer I figured out that it is actually enough to simply remember that OnPreviewDrop() was called.

I work with two drag & drop behavior classes. One for the grid and one for the tree. The OnPreviewDrop() function in the grid class is only called if the drop operation takes place on the grid view. If it takes place on the tree view, the OnPreviewDrop() function in the tree class is called.

So far it seems that this approach works.

Tags
DragAndDrop
Asked by
Rico
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Rico
Top achievements
Rank 1
Share this question
or