RadRadGridView Drag & Drop - limit to same RadGridView?

3 posts, 1 answers
  1. Grand River Rubber
    Grand River Rubber avatar
    6 posts
    Member since:
    Oct 2012

    Posted 04 Aug 2017 Link to this post

    I have a bound RadGridView which I need to allow row reordering for. I followed the example posted by Dess here: http://www.telerik.com/forums/move-rows-with-the-mouse

    And it works perfectly, thank you. I have a question however. When I drag row(s) to another RadGridView, the circle slash icon dissappears which lets the user think they can drag the rows there. They can't however, they're only supposed to drag the rows within the original RadGridView that they're from. Attempting to drag the rows to another RadGridView should show the circle slash icon indicating it's not allowed. Can the example be modified to address this? I'm guessing there's something I might change with e.CanDrop but I'm not sure how to go about this. Thank you.

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3530 posts

    Posted 07 Aug 2017 Link to this post

    Hello Scott, 

    Thank you for writing.  

    As a descendant of RadDragDropService, RadGridViewDragDropService handles the whole drag and drop operation. The PreviewDragOver event allows you to control on what targets the row being dragged can be dropped on. The PreviewDragDrop event allows you to get a handle on all the aspects of the drag and drop operation, the source (drag) grid, the destination (target) control, as well as the row being dragged. This is where we will initiate the actual physical move of the row(s) from one grid to the target control. A sample implementation is demonstrated in the following help article: http://docs.telerik.com/devtools/winforms/gridview/rows/drag-and-drop

    In order to restrict the drag and drop behavior to be only within the same grid, the PreviewDragOver event is the suitable place. It is necessary to check whether the RadGridView on the dragged row and the target row is the same. Here is a sample code snippet: 
    private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
    {
        GridDataRowElement draggedRowElement = e.DragInstance as GridDataRowElement;
        GridDataRowElement targetRowElement = e.HitTarget as GridDataRowElement;
        if (draggedRowElement != null && targetRowElement != null && draggedRowElement.GridControl == targetRowElement.GridControl)
        {
            e.CanDrop = true;
        }
        else
        {
            e.CanDrop = false;
        }
    }


    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Grand River Rubber
    Grand River Rubber avatar
    6 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2017 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you Dess, that works perfectly!
Back to Top