void CustomGridDragAndDrop_Drop(object sender, GridDropEventArgs e) { if (TableView != null) { DropRow(e); TableView = null; e.Handled = true; } }
private void GridPackedDragDropManager_OnDrop(object sender, GridDropEventArgs e) { e.Handled = true; var vm = DataContext as IPackingViewModel; if (vm == null) { return; } switch (_dragSource) { case Packing: if (vm.CanPack()) { vm.Pack(); } break; default: e.Handled = false; break; } }
public void DropRow(GridDropEventArgs args) { var currentRow = LayoutTreeHelper.GetVisualParents(HitElement).Where(row => row is GroupGridRow || row is RowControl).FirstOrDefault() as FrameworkElement; var rowData = currentRow.DataContext as RowData; var tableSource = TableView.Grid.ItemsSource as IList; var dataView = rowData.View as TableView; var dataSource = dataView.Grid.ItemsSource as IList; var rowIndex = dataView.Grid.GetListIndexByRowHandle(args.TargetRowHandle); var draggingRow = DraggingRows[0]; if (dataSource == null || dataSource[0].GetType() != draggingRow.GetType() || dataSource.Count == 0 || draggingRow == rowData.Row) { return; } if (Equals(tableSource, dataSource) && tableSource.IndexOf(DraggingRows[0]) <= rowIndex) { rowIndex--; } tableSource.Remove(DraggingRows[0]); if (!dataView.Grid.IsGrouped) { if (args.DropTargetType == DropTargetType.InsertRowsBefore) { dataSource.Insert(rowIndex, draggingRow); } else if (args.DropTargetType == DropTargetType.InsertRowsAfter) { dataSource.Insert(Math.Min(rowIndex + 1, dataSource.Count), draggingRow); } else { if (Mouse.GetPosition(currentRow).Y >= currentRow.ActualHeight / 2) { dataSource.Insert(Math.Min(rowIndex + 1, dataSource.Count), draggingRow); } else { dataSource.Insert(rowIndex, draggingRow); } } } else if (args.DropTargetType == DropTargetType.InsertRowsIntoGroup || dataView.Grid.IsGrouped) { var value = dataView.Grid.GetCellValue(rowData.RowHandle.Value, dataView.Grid.SortInfo[0].FieldName); TypeDescriptor.GetProperties(draggingRow.GetType())[dataView.Grid.SortInfo[0].FieldName].SetValue(draggingRow, value); if (args.DropTargetType == DropTargetType.InsertRowsAfter) { dataSource.Insert(Math.Min(rowIndex + 1, dataSource.Count), draggingRow); } else { dataSource.Insert(rowIndex, draggingRow); } dataView.Grid.RefreshData(); } }