|
protected override void ProcessOnDrop(DragEventArgs args, RowColumnIndex rowColumnIndex)
{
SfDataGrid sourceDataGrid=null;
if (args.Data.GetDataPresent("ListView"))
listview = args.Data.GetData("ListView") as ListView;
else if (args.Data.GetDataPresent("SourceDataGrid"))
sourceDataGrid = args.Data.GetData("SourceDataGrid") as SfDataGrid;
//When we dragging the records from the other SfDataGrid, we need to call the base function of the ProcessOnDrop and no need to execute the further code for this method.
if (sourceDataGrid != null)
{
base.ProcessOnDrop(args, rowColumnIndex);
return;
}
if (!DataGrid.SelectionController.CurrentCellManager.CheckValidationAndEndEdit())
return;
//To get the dropping position of the record
var dropPosition = GetDropPosition(args, rowColumnIndex, draggingRecords);
if (dropPosition == DropPosition.None)
return;
// to get the index of dropping record
var droppingRecordIndex = this.DataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex);
if (droppingRecordIndex < 0)
return;
// to insert the dragged records based on dropping records index
foreach (var record in draggingRecords)
{
if (listview != null)
{
(listview.ItemsSource as ObservableCollection<Orders>).Remove(record as Orders);
var sourceCollection = this.DataGrid.View.SourceCollection as IList;
if (dropPosition == DropPosition.DropBelow)
sourceCollection.Insert(droppingRecordIndex + 1, record);
else
sourceCollection.Insert(droppingRecordIndex, record);
}
else
{
var draggingIndex = this.DataGrid.ResolveToRowIndex(draggingRecords[0]);
if (draggingIndex < 0)
{
return;
}
// to get the index of dragging row
var recordindex = this.DataGrid.ResolveToRecordIndex(draggingIndex);
// to ger the record based on index
var recordEntry = this.DataGrid.View.Records[recordindex];
this.DataGrid.View.Records.Remove(recordEntry);
// to insert the dragged records to particular position
if (draggingIndex < rowColumnIndex.RowIndex && dropPosition == DropPosition.DropAbove)
this.DataGrid.View.Records.Insert(droppingRecordIndex - 1, this.DataGrid.View.Records.CreateRecord(record));
else if (draggingIndex > rowColumnIndex.RowIndex && dropPosition == DropPosition.DropBelow)
this.DataGrid.View.Records.Insert(droppingRecordIndex + 1, this.DataGrid.View.Records.CreateRecord(record));
else
this.DataGrid.View.Records.Insert(droppingRecordIndex, this.DataGrid.View.Records.CreateRecord(record));
}
}
//Closes the Drag arrow indication all the rows
CloseDragIndicators();
//Closes the Drag arrow indication all the rows
CloseDraggablePopUp();
}
} |
|
private void ListView_Drop(object sender, DragEventArgs e)
{
foreach (var item in records)
{
//Remove the record from first datagrid while drop to ListView
this.sfDataGrid.View.Remove(item as Orders);
//Remove the record from second datagrid while drop to ListView
this.sfDataGrid2.View.Remove(item as Orders);
(this.DataContext as ViewModel).OrderDetails1.Add(item as Orders);
}
} |
|
public MainWindow()
{
InitializeComponent();
//Assign the customized RowDragDropController for first datagrid.
this.sfDataGrid.RowDragDropController = new GridRowDragDropControllerExt();
//Assign the customized RowDragDropController for second datagrid.
this.sfDataGrid2.RowDragDropController = new GridRowDragDropControllerExt();
this.listView.DragOver += ListView_DragOver;
this.listView.PreviewMouseMove += ListView_PreviewMouseMove;
this.listView.Drop += ListView_Drop;
} |