Best way to save changes back to DataTable

I have a sfdatagrid that users can move position of rows, sort, add rows, remove rows and edit the fileds. What is the best way to save this back to the DataTable as multiple sfdatagrids display this data. I want to avoid having to refresh the datatable from the SQL database to get access to the changes the user has made to the sfdatagrids.

Thanks, Martin

1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team November 19, 2020 01:09 PM UTC

Hi Martin,

Thank you for using Syncfusion controls. 

By default, when the cell leaves from editing it will automatically update the view of grid alone to refresh the changes. It will affect only the view properties of the grid and will not update the changes to the underlying source file. 
You could update your underlying data source file manually. To update the changes of the Data Source (grid level changes) to the underlying source file when the cell leaves from editing, you can end editing of       cell update the cell or data changes by using SfDataGrid.CurrentCellEndEdit event. Please refer the below code snippet, 
sfDataGrid1.CurrentCellEndEdit += SfDataGrid1_CurrentCellEndEdit;

private void SfDataGrid1_CurrentCellEndEdit(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellEndEditEventArgs e) 
            //You can add your codes here to save the data or cell changes. 

You could update the database of added or deleted row by using SfDataGrid.View.Records.CollectionChanged event. Please refer the below code snippet, 
sfDataGrid1.View.Records.CollectionChanged += Records_CollectionChanged;

private void Records_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
            //You can add your codes here to save the added or delete row data changes. 

We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Marked as answer
Loader.
Up arrow icon