I'm using DevExpress 19.2, .NET Framework 4.6.1, C#, Visual Studio 2017, WinForms. I want to move data from one DevExpress grid to another. I've been unable to find a complete example online, but have cobbled together data from multiple sources. Unfortunately, I can't quite get it right. Can someone explain what I'm missing or point me to a working example?
My first attempts come based on info from this link: https://docs.devexpress.com/WindowsForms/118656/common-features/behaviors/drag-and-drop-behavior#how-to-customize-drag-and-drop-operations. It works, but I have to hard code the name of the GridControl in the code. This works as a proof-of-concept, but eventually, I'll have multiple grids and I'll need to find what GridControl it's for. The DragDropEventsArgs have the GridView data, but I haven't been able to find the GridControl data.
Here's how it looks after I drag the data from one grid to another:

Here is the code:
private void dragDropEvents2_DragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e)
{
DragDropEvents dde = (DragDropEvents)sender;
BindingSource bs = (BindingSource)dde.Container.Components[0];
CustomerWorkOrderViewModel wo = (CustomerWorkOrderViewModel)bs.Current;
//GridView target = (GridView)e.Target;
GridView target = (GridView)e.Target;
BindingSource bsTarget = (BindingSource)target.DataSource;
SortableBindingList<CustomerWorkOrderViewModel> sblTarget =
(SortableBindingList<CustomerWorkOrderViewModel>)bsTarget.DataSource;
List<CustomerWorkOrderViewModel> listWo = sblTarget.ToList();
if (listWo == null)
{
listWo = new List<CustomerWorkOrderViewModel>();
}
if (listWo.Where(x => x.customerWorkOrderID == wo.customerWorkOrderID).Count() == 0)
{
listWo.Add(wo);
gridControl2.DataSource = listWo;
gridControl2.RefreshDataSource();
}
e.Handled = true;
}
The part I need to change is hard coding GridControl name in the code:

The second attempt I found is from this link: https://docs.devexpress.com/WindowsForms/DevExpress.Utils.DragDrop.DragDropEvents.DragDrop. It's not quite right because it's from a TreeView to a GridView, but I've been able to change the TreeView part. The part that doesn't work is adding data to the new grid. The example shows adding a new row to the grid and then getting the handle. However, when I use the code to get the handle, it gives me a negative value. I tried hard coding the row handle as 0, but it give me a mismatch of blank data and the data I want to add:
Here's the code example:
private void dragDropEvents1_DragDrop(object sender, DragDropEventArgs e) {
List<TreeListNode> list = e.Data as List<TreeListNode>;
foreach (TreeListNode node in list) {
gridView1.AddNewRow();
gridView1.SetRowCellValue(GridControl.NewItemRowHandle, gridView1.Columns["DEPARTMENT"], node.GetValue(colDEPARTMENT1));
}
e.Handled = true;
}
Here's the code for this version:
private void dragDropEvents2_DragDrop(object sender, DevExpress.Utils.DragDrop.DragDropEventArgs e)
{
DragDropEvents dde = (DragDropEvents)sender;
BindingSource bs = (BindingSource)dde.Container.Components[0];
CustomerWorkOrderViewModel wo = (CustomerWorkOrderViewModel)bs.Current;
GridView target = (GridView)e.Target;
BindingSource bsTarget = (BindingSource)target.DataSource;
SortableBindingList<CustomerWorkOrderViewModel> sblTarget =
(SortableBindingList<CustomerWorkOrderViewModel>)bsTarget.DataSource;
List<CustomerWorkOrderViewModel> listWo = sblTarget.ToList();
if (listWo == null)
{
listWo = new List<CustomerWorkOrderViewModel>();
}
if (listWo.Where(x => x.customerWorkOrderID == wo.customerWorkOrderID).Count() == 0)
{
target.AddNewRow();
target.SetRowCellValue(0, target.Columns[0], wo.customerWorkOrderID);
gridControl2.RefreshDataSource();
}
e.Handled = true;
}
