views:

125

answers:

1

Hi,

When using databindings with OnPropertyChanged as updateDataSourceMode the data source is updated 2 times (OnPropertychanged and OnValidation) : 1- after TextChanged for textbox, CheckedChanged for checkbox, SelectedValueChanged for comboBox... 2- after Validation

I will explain more with an example : assume we have an Employee class with a boolean propertie IsManager, this propertie is bounded to a checkbox in a form in this way : checkboxIsMgr.DataBindings.Add("Checked",employee,"IsManager",false,OnPropertyChanged);

when checkboxIsMgr is checked/unchecked the IsManager propertie setter is called and when moving to another control (the checkbox lost the focus and the Validation event is called) the IsManager propertie setter is called again.

How can I avoid the second data source update without modifying the updateDataSourceMode to OnValidation?

Best regards

+1  A: 

This can be done by setting the CausesValidation propertie for the control to false, this prevent data source to be updated second time but this also prevent the Validating event to be raised!!

Bilel Boughanmi