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

RadGridView: Avoid DragAndDrop while scrolling or resizing columns

3 Answers 68 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 29 Aug 2017, 07:13 AM

I have DragAndDrop enabled on a RadGridView. This works, but when I want to scroll or I try to resize the column header a dragAndDrop action is also started that prevents the scrolling or resizing.

How can I detect that the DragAndDrop event started on a scrollbar or a column header and stop the event?

Solutions I found on the telerik page are all with the old RadDragDropManager and not with the DragDropManager that should now be used. I can't find the equivalent function for e.GetElement<T> that was called on the  in the DragDropQueryEventArgs. This would be called in the DragInitializeHandler.

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 31 Aug 2017, 02:22 PM
Hello Roland,

Please have a look at the DragDropManager Migration article if you have not done so already as it describes how to migrate from using the old RadDragAndDropManager to the new DragDropManager.

As suggested there, you should handle the DragInitialize method inside of which you can get the and check whether it's inside the visual tree of the ScrollBar or GridViewHeaderCell by using the ParentOfType<T> extension method.

A good example of how this can be done has been demonstrated in the Tree to Grid Drag demo from the WPF Controls Samples.

I hope you find this information helpful. Do let me know if you need any further assistance on the matter. If that is the case, please provide more information on your exact requirements and possibly a sample project demonstrating your current approach.

I'm looking forward to your reply.

Regards,
Dilyan Traykov
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Roland
Top achievements
Rank 1
answered on 12 Sep 2017, 07:01 AM

I was not able to get it to work with the proposed solution, as always at least one event was sent with the OriginalSource RadGridView.

My Solution now is based on the solution by Aleksander:

private void OnDragInitialize(object sender, DragInitializeEventArgs e)
{
  var gridView = sender as MSGridView;
  if (gridView != null)
  {
    // don't start drag and drop while scrolling or resizing grid headers ...
    if (IsTypeHit(gridView, e.RelativeStartPoint, new[] { typeof(ScrollBar), typeof(GridViewHeaderRow) }))
    {
      e.Cancel = true;
      return;
    }
    // (…)
  }
}
 
private static bool IsTypeHit(Visual reference, Point point, Type[] types)
{
  var htr = VisualTreeHelper.HitTest(reference, point);
  var parent = htr.VisualHit;
  while (parent != null && types.All(t => t != parent.GetType()))
  {
    parent = VisualTreeHelper.GetParent(parent);
  }
 
  return parent != null;
}

0
Dilyan Traykov
Telerik team
answered on 12 Sep 2017, 09:58 AM
Hello Roland,

I'm glad to hear that you've found a suitable solution. Thank you for sharing it with the community.

If you require any further assistance, do not hesitate to contact us again.

Regards,
Dilyan Traykov
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
DragAndDrop
Asked by
Roland
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Roland
Top achievements
Rank 1
Share this question
or