|
1 | | -# How to get the target record when drop the row in WPF DataGrid(SfDataGrid)? |
| 1 | +# How to Get the Target Record when Drop the Row in WPF DataGrid? |
2 | 2 |
|
3 | | -## About the sample |
| 3 | +This example illustrates how to get the target record when drop the row in [WPF DataGrid](https://www.syncfusion.com/wpf-controls/datagrid) (SfDataGrid). |
4 | 4 |
|
5 | | -This example illustrates how to get the target record when drop the row in [WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid)? |
6 | | - |
7 | | -[WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid) does not provide the direct support to get the target record which is going to drop. You can get the target record which is going to drop by using [SfDataGrid.RowDragDropController.Drop](https://help.syncfusion.com/cr/cref_files/wpf/Syncfusion.SfGrid.WPF~Syncfusion.UI.Xaml.Grid.GridRowDragDropController~Drop_EV.html) event. |
| 5 | +`DataGrid` does not provide the direct support to get the target record which is going to drop. You can get the target record which is going to drop by using [SfDataGrid.RowDragDropController.Drop](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.GridRowDragDropController.html#Syncfusion_UI_Xaml_Grid_GridRowDragDropController_Drop) event. |
8 | 6 |
|
9 | 7 | ```C# |
10 | 8 | sfDataGrid.RowDragDropController.Drop += RowDragDropController_Drop; |
11 | 9 |
|
12 | 10 | private void RowDragDropController_Drop(object sender, GridRowDropEventArgs e) |
13 | 11 | { |
14 | | - var droppedIndex = (int)e.TargetRecord; |
15 | | - |
16 | | - var rowIndex = this.sfDataGrid.ResolveToRowIndex(droppedIndex); |
17 | | - |
18 | | - NodeEntry recordEntry = null; |
19 | | - |
20 | | - if (this.sfDataGrid.View.TopLevelGroup != null) |
21 | | - recordEntry = this.sfDataGrid.View.TopLevelGroup.DisplayElements[this.sfDataGrid.ResolveToRecordIndex(rowIndex)]; |
22 | | - else |
23 | | - recordEntry = this.sfDataGrid.View.Records[this.sfDataGrid.ResolveToRecordIndex(rowIndex)]; |
24 | | - |
25 | | - var targetRecord = ((recordEntry as RecordEntry).Data as OrderInfo); |
26 | | - |
27 | | - txtDisplayRecord.Text = "OrderId : " + targetRecord.OrderID + "\nCustomerID : " + targetRecord.CustomerID + "\nCustomerName : " + targetRecord.CustomerName + "\nCountry : " + targetRecord.Country + "\nUnitPrice : " + targetRecord.UnitPrice + "\nRow Index :" + droppedIndex; |
| 12 | + var droppedIndex = (int)e.TargetRecord; |
| 13 | + var rowIndex = this.sfDataGrid.ResolveToRowIndex(droppedIndex); |
| 14 | + NodeEntry recordEntry = null; |
| 15 | + |
| 16 | + if (this.sfDataGrid.View.TopLevelGroup != null) |
| 17 | + recordEntry = this.sfDataGrid.View.TopLevelGroup.DisplayElements[this.sfDataGrid.ResolveToRecordIndex(rowIndex)]; |
| 18 | + else |
| 19 | + recordEntry = this.sfDataGrid.View.Records[this.sfDataGrid.ResolveToRecordIndex(rowIndex)]; |
| 20 | + |
| 21 | + var targetRecord = ((recordEntry as RecordEntry).Data as OrderInfo); |
| 22 | + |
| 23 | + txtDisplayRecord.Text = "OrderId : " + targetRecord.OrderID + "\nCustomerID : " + targetRecord.CustomerID + "\nCustomerName : " + targetRecord.CustomerName + "\nCountry : " + targetRecord.Country + "\nUnitPrice : " + targetRecord.UnitPrice + "\nRow Index :" + droppedIndex; |
28 | 24 | } |
29 | | - |
30 | 25 | ``` |
31 | 26 |
|
32 | | -KB article - [How to get the target record when drop the row in WPF DataGrid(SfDataGrid)?](https://www.syncfusion.com/kb/11377/how-to-get-the-target-record-when-drop-the-row-in-wpf-datagrid-sfdatagrid) |
33 | | - |
34 | | -## Requirements to run the demo |
35 | | -Visual Studio 2015 and above versions |
| 27 | + |
0 commit comments