Multiple Row Data drag and drop
Please Help
Attachment: RowDragAndDropBetweenControls_72494a05.rar
I want a multiple colonns dras and drop but when I drag from the second columns to to first the record moved is not deleted
Check the sample
Please help
Attachment: RowDragAndDropBetweenControls_72494a05.rar
SIGN IN To post a reply.
5 Replies
JG
Jai Ganesh S
Syncfusion Team
July 2, 2018 11:48 AM UTC
Hi Julien,
We have checked your query with your attached sample. In your sample, you have used two SfDataGrid and ListView. By default, the drag and drop will be worked between two SfDataGrid without doing any customization. Could you please refer the below KB link to show the drag and drop between two SfDataGrid.
KB Link:
You have customized the ProcessOnDrop method due to drag and drop between SfDataGrid and ListView. Hence the drag and drop will not be worked while you drag the rows from another DataGrid. However, you can resolve this problem by adding the below code in ProcessOnDrop method,
|
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();
}
} |
Regards,
Jai Ganesh S
JB
Julien Breton
July 2, 2018 12:10 PM UTC
Ok thanks but when I want to remove data from the second sfdatagrid to the list , the selected record moved is not delete.
Attachment: Drag_and_Drop_02_07_2018_14_09_16_3c846273.rar
Check the videos in the zip
Thanks
Attachment: Drag_and_Drop_02_07_2018_14_09_16_3c846273.rar
JG
Jai Ganesh S
Syncfusion Team
July 3, 2018 12:31 PM UTC
Hi Julien,
You can achieve your requirement to remove the item from the second datagrid while drag drop the record from second datagrid to ListView by adding the below code in ListViewDrop event.
|
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);
}
} |
Regards,
Jai Ganesh S
JB
Julien Breton
July 3, 2018 12:42 PM UTC
Nice thanks
But why I can't drop item from the list to the second row ?
JG
Jai Ganesh S
Syncfusion Team
July 5, 2018 11:28 AM UTC
Hi Julien,
In the sample, you didn’t assign the customized RowDragDropController in second datagrid. Hence, you can’t drop item from the list to the second DataGrid. You can achieve this by declare the customized RowDragDropController in second SfDataGrid (sfDataGrid2) like below,
|
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;
} |
Regards,
Jai Ganesh S
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
JB Julien Breton
- Jun 29, 2018 03:00 PM UTC
- Jul 5, 2018 11:28 AM UTC