RadGridView: Avoid DragAndDrop while scrolling or resizing columns

4 posts, 0 answers
  1. Roland
    Roland avatar
    4 posts
    Member since:
    Aug 2017

    Posted 29 Aug Link to this post

    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.

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 31 Aug Link to this post

    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 OriginalSource 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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Roland
    Roland avatar
    4 posts
    Member since:
    Aug 2017

    Posted 12 Sep Link to this post

    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;
    }

  4. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 12 Sep Link to this post

    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.
Back to Top