BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
Column Drag And Drop |
You can enable column drag and drop in SfDataGrid by setting AllowDraggingColumns property as true. You can refer the dashboard sample for the column drag and drop feature from the below locations.
Dashboard installed location: C:\Users\Public\Documents\Syncfusion\WPF\{installed version}\SfGrid.WPF\Samples\ColumnChooserDemo GitHub location: You can also refer the below documentation for more details on it https://help.syncfusion.com/wpf/datagrid/columns#column-drag-and-drop |
Row Drag And Drop |
You can enable row drag and drop in SfDataGrid by setting AllowDraggingRows and AllowDrop property as true. You can refer the dashboard sample for the row drag and drop feature from the below locations.
Dashboard installed location: C:\Users\Public\Documents\Syncfusion\WPF\\{installed version}\SfGrid.WPF\Samples\DragAndDropDemo GitHub location: https://github.com/syncfusion/wpf- demos/tree/master/SfGrid.WPF/Samples/DragAndDropDemo
You can also refer the below documentation for more details on it
https://help.syncfusion.com/wpf/datagrid/interactive-features#drag-and-drop-rows |
AssociatedObject.RowDragDropController.Dropped += sfGrid_Dropped;
private void sfGrid_Dropped(object sender, GridRowDroppedEventArgs e)
{
if (e.DropPosition != DropPosition.None)
{
//Get Dragging records
ObservableCollection<object> draggingRecords = e.Data.GetData("Records") asObservableCollection<object>;
//Gets the TargetRecord from the underlying collection using record index of the TargetRecord (e.TargetRecord)
ViewModel model = AssociatedObject.DataContext as ViewModel;
OrderInfo targetRecord = model.OrdersFirstGrid[(int)e.TargetRecord];
//Use Batch update to avoid data operatons in SfDataGrid during records removing and inserting
AssociatedObject.BeginInit();
//Removes the dragging records from the underlying collection
foreach (OrderInfo item in draggingRecords)
{
model.OrdersFirstGrid.Remove(item);
}
//Find the target record index after removing the records
int targetIndex = model.OrdersFirstGrid.IndexOf(targetRecord);
int insertionIndex = e.DropPosition == DropPosition.DropAbove ? targetIndex : targetIndex + 1;
insertionIndex = insertionIndex < 0 ? 0 : insertionIndex;
//Insert dragging records to the target position
for (int i = draggingRecords.Count - 1; i >= 0; i--)
{
model.OrdersFirstGrid.Insert(insertionIndex, draggingRecords[i] as OrderInfo);
}
AssociatedObject.EndInit();
}
}
|