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. Image for the cookie policy date

OneWay Data Binding is updating data source

Good Evening,

I'm having an issue with the SfDataGrid control using the OneWay Data Binding, where the data in the source collection is being updated when making changes in the SfDataGrid even though I'm using OneWay Binding Mode (I've also tried to use OneTime binding with the same results).

Here is the XAML where I define the SfDataGrid showing the binding parameters used:

<syncfusion:SfDataGrid ColumnSizer="Auto" AllowEditing="True" MinHeight="200" MaxHeight="400" MinWidth="300" x:Name="sdgEngineers" ItemsSource="{Binding EngineersContract.Engineers, diag:PresentationTraceSources.TraceLevel=High, Mode=OneTime}" AutoGenerateColumns="True" CurrentCellValidating="CurrentCellValidating" AddNewRowPosition="FixedTop" AddNewRowInitiating="sdgEngineers_AddNewRowInitiating" RowValidating="RowValidating" SelectionMode="Extended" AutoGeneratingColumn="AutoGeneratingColumns" LiveDataUpdateMode="Default" />

Is this a bug that I've found or am I simply misunderstanding how One Way (and One Time) binding should work?

If anyone has experienced this issue and has a workaround, I'd be eager to learn it because I need to get past this issue as soon as I possibly can.

Please let me know if you need any further information?

Kind Regards,
Luke

3 Replies

SV Srinivasan Vasu Syncfusion Team September 13, 2016 09:18 AM UTC

Thanks for contacting Syncfusion support.  
 
We have analyzed your query “One Way binding updates the data source.”  Are you editing or deleting the records in SfDataGrid. By Default SfDataGrid Editing and Deleting operations are not related to the ItemsSource binding.  
  
Find the details below,  
1.     While editing the data, it will update the changes in your underlying data object, as TwoWay Binding will be created with Data.   
2.     While deleting the data object in SfDataGrid, SfDataGrid updates the collection.   
  
If you want to validate the data being editing, you can use data validation feature,  
  
Basically SfDataGrid will display the actual data from underlying collection. Please let us know your requirement clearly, so that we can provide exact solution to meet your requirement.
  
Regards,
Srinivasan
  
 



LF Luke Foley September 13, 2016 01:07 PM UTC

Good Afternoon,

First and foremost thank you for coming back to me on this and apologies if my original question did not clarify my intentions.

My requirements for the SfDataGrid are as follows:

  • SfDataGrids Item Source will be bound to an ObservableCollection using OneWay binding (I don't want new rows or deleted rows to be commited back to the original data source)
  • When editing the existing rows in the SfDataGrid I would also like this to be done using OneWay binding (I want to be able to edit the data in the grid and keep the values in the original ObservableCollection untouched)
  • Once Cell/Row Validation has been completed and the user clicks on Save, I would then like to commit the data back from the SfDataGrid to the ObservableCollection ready for it to be sent back to our server using WCF
Is this something that I can do easily using SfDataGrid? I did attempt the following in the AutoGeneratingColumn event but it doesn't seem to work as I expected

private void AutoGeneratingColumns(object sender, Syncfusion.UI.Xaml.Grid.AutoGeneratingColumnArgs e)
{
Binding OneWayBinding = new Binding(e.Column.MappingName);
OneWayBinding.Mode = BindingMode.OneWay;
e.Column.ValueBinding = OneWayBinding;
e.Column.UseBindingValue = true;
}

Kind Regards,
Luke


SP Sowndaiyan Paulpandi Syncfusion Team September 15, 2016 03:23 AM UTC

Hi Luke

You can able to commit the changes in button click by using the below code example,

C#

 
private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            if (this.dataGrid.SelectionController.CurrentCellManager != null) 
 
                this.dataGrid.SelectionController.CurrentCellManager.EndEdit(true); 
        }

 

And also in SfDataGrid have the built-in validation support, that allows you to validate the data and display hints in case of validation is not passed. In case of invalid data, error icon is displayed at the top right corner of GridCell. When mouse over the error icon, error information will be displayed in tooltip.

We have prepared a sample to perform the DataValidation before commit the values and you can download the sample from the below location,


Sample : http://www.syncfusion.com/downloads/support/forum/125935/ze/CS-1240563135 

Regards,
Sowndaiyan
  


Loader.
Up arrow icon