Skip to content

Commit 7cee95b

Browse files
authored
How to get the target record when drop the row in WPF DataGrid(SfDataGrid)?
How to get the target record when drop the row in WPF DataGrid(SfDataGrid)?
1 parent 9fc101e commit 7cee95b

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
1-
# how-to-get-the-target-record-when-drop-the-row-in-wpf-data-grid
2-
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(SfDataGrid)?
2+
3+
## About the sample
4+
This example illustrates how to get the target record when drop the row in WPF DataGrid(SfDataGrid)?
5+
6+
By default, 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 event.
7+
8+
```C#
9+
sfDataGrid.RowDragDropController.Drop += RowDragDropController_Drop;
10+
11+
private void RowDragDropController_Drop(object sender, GridRowDropEventArgs e)
12+
{
13+
var droppedIndex = (int)e.TargetRecord;
14+
15+
var rowIndex = this.sfDataGrid.ResolveToRowIndex(droppedIndex);
16+
17+
NodeEntry recordEntry = null;
18+
19+
if (this.sfDataGrid.View.TopLevelGroup != null)
20+
recordEntry = this.sfDataGrid.View.TopLevelGroup.DisplayElements[this.sfDataGrid.ResolveToRecordIndex(rowIndex)];
21+
else
22+
recordEntry = this.sfDataGrid.View.Records[this.sfDataGrid.ResolveToRecordIndex(rowIndex)];
23+
24+
var targetRecord = ((recordEntry as RecordEntry).Data as OrderInfo);
25+
26+
txtDisplayRecord.Text = "OrderId : " + targetRecord.OrderID + "\nCustomerID : " + targetRecord.CustomerID + "\nCustomerName : " + targetRecord.CustomerName + "\nCountry : " + targetRecord.Country + "\nUnitPrice : " + targetRecord.UnitPrice + "\nRow Index :" + droppedIndex;
27+
}
28+
29+
```
30+
31+
## Requirements to run the demo
32+
Visual Studio 2015 and above versions

0 commit comments

Comments
 (0)