Moving rows action
Hi! I have a SFDataGrid backed by an ObservableCollection of a custom class. I need moving columns: 
to update the Z axis in my scatter plot (which series' mark is on top of the other). It would probably work if I moved the entries in my ObservableCollection around on a row move, but I don't know if there's a XAML property for that, and if there was how I'd know which are moving. Any help appreciated thanks!
SIGN IN To post a reply.
7 Replies
FP
Farjana Parveen Ayubb
Syncfusion Team
June 26, 2019 12:24 PM UTC
Hi Nick,
Thank you for contacting Syncfusion Support.
We have analyzed your query but we cannot get your requirement clearly. From your update, we suspect that your requirement is to drag and drop columns and rows in grid. SfDataGrid has inbuilt support for Row/Column drag and drop. Please find the details below
|
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 |
If your requirement is different from the above, please revert us with more details on your requirement using images/videos. It will helps us to investigate further and provide earlier prompt solution.
Regards,
Farjana Parveen A
FP
Farjana Parveen Ayubb
Syncfusion Team
June 27, 2019 06:02 AM UTC
Hi Nick,
Thanks for the update.
We have analyzed your query. And we suspect that your requirement is to reorder the underlying collection based on the visual order after drag and drop. And this can be achieved by handling RowDragDropController.Droppedevent. Please refer to the below code snippet
|
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();
}
}
|
Also please find sample for the same from the link below
Sample Link:
Please let us know, if we misunderstood your requirement.
Regards,
Farjana Parveen A.
NB
Nick Beule
June 27, 2019 06:42 PM UTC
perfect thanks so much!
FP
Farjana Parveen Ayubb
Syncfusion Team
June 28, 2019 05:51 AM UTC
Hi Nick,
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you.
Regards,
Farjana Parveen A
NB
Nick Beule
June 28, 2019 01:39 PM UTC
for some reason I cant get access to the .Dropped event:
. do I need to include something other than Syncfusion.UI.Xaml.Grid?
FP
Farjana Parveen Ayubb
Syncfusion Team
July 1, 2019 08:42 AM UTC
Hi Nick,
We have analyzed your query. We have provided built-in event support to customize drag and drop operations from the version 16.3.0.21. Please refer to the below release notes
Could you please verify whether you are using the same version (16.3.0.21) or later? If not we request you to upgrade your version to 16.3.0.21 or later.
Regards,
Farjana Parveen A
SIGN IN To post a reply.
- 7 Replies
- 2 Participants
-
NB Nick Beule
- Jun 25, 2019 08:15 PM UTC
- Jul 1, 2019 08:42 AM UTC