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

RadRadGridView Drag & Drop - limit to same RadGridView?

2 Answers 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Grand River Rubber
Top achievements
Rank 2
Grand River Rubber asked on 04 Aug 2017, 05:45 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Aug 2017, 08:52 AM
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.
0
Grand River Rubber
Top achievements
Rank 2
answered on 07 Aug 2017, 01:17 PM
Thank you Dess, that works perfectly!
Tags
GridView
Asked by
Grand River Rubber
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Grand River Rubber
Top achievements
Rank 2
Share this question
or