Disallow dropping on source

4 posts, 0 answers
  1. Rico
    Rico avatar
    2 posts
    Member since:
    Jun 2018

    Posted 19 Jun 2018 Link to this post

    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?

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2159 posts

    Posted 22 Jun 2018 Link to this post

    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.
  3. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2159 posts

    Posted 22 Jun 2018 Link to this post

    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.
  4. Rico
    Rico avatar
    2 posts
    Member since:
    Jun 2018

    Posted 22 Jun 2018 in reply to Martin Ivanov Link to this post

    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.

Back to Top