We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Drag and Drop Between SfdataGrid Issue

Hello Team,

In the below link Drag and drop between SFDatagrid happen but I want to do some operation at the time of drop from one grid to another grid. Is there any event where we can get the drop position with the record and the grid which initiated the drag?

Thanks
Harshul



3 Replies

JN Jayaleshwari N Syncfusion Team January 30, 2019 10:47 AM UTC

Hi Harshul, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked the reported query “Is there any event where we can get the drop position with the record and the grid which initiated the drag” from our side. You can make use of Dragging and Dropped event of RowDragAndDropController. 
 
Code snippet: Event to know the datagrid which initiated the drag. You can get the initiated datagrid form sender. 
 
this.dataGrid1.RowDragDropController.DragStart += RowDragDropController_DragStart; 
private void RowDragDropController_DragStart(object sender, Syncfusion.UI.Xaml.Grid.GridRowDragStartEventArgs e) 
{ 
             
} 
 
Code snippet: Event to know that the drop position from the event args of Dropped event. 
 
this.dataGrid2.RowDragDropController.Dropped += RowDragDropController_Dropped; 
 
private void RowDragDropController_Dropped(object sender, Syncfusion.UI.Xaml.Grid.GridRowDroppedEventArgs e) 
{ 
             
} 
 
Please find the details about GridRowDroppedEventArgs details 
 
  • Data : Gets or sets a data object that contains the data associated when dragging the rows.
  • DropPosition : Gets a value that indicates the drop position based on the dropped location.   
  • IsFromOutSideSource : Gets a value that indicates whether the dragging item is from the same datagrid
  • TargetRecord: Gets a value that indicates the target record, which is going to be dropped
 
We already have a task to update the Drag and Drop with data grid in our user guide documentation. We will shortly update the documentation. 
 
Please let us know if you would require further assistance. 
 
Regards, 
Jayaleshwari N. 



BR Brijesh January 31, 2019 10:22 AM UTC

Hi,

In the below sample how will we get drop location and record(data) in the second grid in which I have applied below event. please update below sample.

this.dataGrid2.RowDragDropController.Dropped += RowDragDropController_Dropped; 
 
private void RowDragDropController_Dropped(object sender, Syncfusion.UI.Xaml.Grid.GridRowDroppedEventArgs e) 
{ 
             
} 
Thanks 
Harshul


JN Jayaleshwari N Syncfusion Team February 1, 2019 07:16 AM UTC

Hi Harshul, 
 
Sorry for the inconvenience. 
 
We have modified the sample to achieve your requirement by using RowDragDropController. You will get dropped record, dropped location and source that initiated the dragging in ProcessOndrop override method. 
 
Code snippet C#: dropped record, location and initiated source get in ProcessOnDrop method. 
 
public class RowDragDropControllerExt : GridRowDragDropController 
{                 
    protected override void ProcessOnDrop(DragEventArgs args, RowColumnIndex rowColumnIndex) 
    { 
        base.ProcessOnDrop(args, rowColumnIndex); 
        var dropPosition = args.GetPosition(this.DataGrid);     // drop location dragged record.        
        var record = this.DataGrid.GetRecordAtRowIndex(rowColumnIndex.RowIndex);    // Dropped record. 
        if (args.Data.GetDataPresent("SourceDataGrid")) 
        { 
            var sourceDataGrid = args.Data.GetData("SourceDataGrid") as SfDataGrid;      // DataGrid that initated event. 
        } 
    }         
} 
                               
Code snippet C#: Extended RowDragDropControllerExt assigned to DataGrid’s RowDragDropController. 
 
public class SfDataGridBehavior   : Behavior<SfDataGrid> 
{ 
    protected override void OnAttached() 
    { 
        base.OnAttached(); 
        this.AssociatedObject.RowDragDropController = new RowDragDropControllerExt(); 
    } 
} 
 
We have attached the tested sample for your reference and you can download the same from the following location. 
 
Please let us know if you would require further assistance. 
 
Regards, 
Jayaleshwari N. 


Loader.
Live Chat Icon For mobile
Up arrow icon