We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Moving rows action

Thread ID:

Created:

Updated:

Platform:

Replies:

145501 Jun 25,2019 08:15 PM UTC Jul 1,2019 08:42 AM UTC WPF 7
loading
Tags: SfDataGrid
Nick Beule
Asked On June 25, 2019 08:15 PM UTC

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!

Farjana Parveen Ayubb [Syncfusion]
Replied On 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 


Nick Beule
Replied On June 26, 2019 12:54 PM UTC



Attachment: Captures_e5d7c2cd.zip

Farjana Parveen Ayubb [Syncfusion]
Replied On 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. 


Nick Beule
Replied On June 27, 2019 06:42 PM UTC

perfect thanks so much!

Farjana Parveen Ayubb [Syncfusion]
Replied On 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 


Nick Beule
Replied On 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?

Farjana Parveen Ayubb [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon