Articles in this section
Category / Section

How to get the target record when drop the row in WPF DataGrid (SfDataGrid)?

WPF DataGrid (SfDataGrid) provides the Row Drag and Drop support. You can get the target record which is going to drop by using SfDataGrid.RowDragDropController.Drop event.

sfDataGrid.RowDragDropController.Drop += RowDragDropController_Drop;private void RowDragDropController_Drop(object sender, GridRowDropEventArgs e)
{
            var droppedIndex = (int)e.TargetRecord;
 
            var rowIndex = this.sfDataGrid.ResolveToRowIndex(droppedIndex);
 
            NodeEntry recordEntry = null;
 
            if (this.sfDataGrid.View.TopLevelGroup != null)
                recordEntry = this.sfDataGrid.View.TopLevelGroup.DisplayElements[this.sfDataGrid.ResolveToRecordIndex(rowIndex)];            
            else
                recordEntry = this.sfDataGrid.View.Records[this.sfDataGrid.ResolveToRecordIndex(rowIndex)];
 
            var targetRecord = ((recordEntry as RecordEntry).Data as OrderInfo);
            
            txtDisplayRecord.Text = "OrderId : " + targetRecord.OrderID + "\nCustomerID : " + targetRecord.CustomerID + "\nCustomerName : " + targetRecord.CustomerName + "\nCountry : " + targetRecord.Country + "\nUnitPrice : " + targetRecord.UnitPrice + "\nRow Index :" + droppedIndex;
}


Get the target record when drop the row in SfDataGrid

View WPF DataGrid Drag and Drop Demo in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied