When a bool property in my BO is bound to a CheckBox in a form, while after clicking the checkbox I have to change the focus by clicking somewhere else. Only then the BO gets updated.
To overcome this I have used the following remedy which may not be a better solution but it solves it. If anybody know a better one please suggest me.
Private Sub DiscountCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DiscountCheckBox.CheckedChanged
If DiscountCheckBox.Focused Then
Dim localBO As BO = CType(BOBindingSource.Current, BO)
If localBO IsNot Nothing Then
localBO.DiscountAllowed = DiscountCheckBox.Checked
DiscountCheckBox.Invalidate()
DiscountCheckBox .Update()
End If
End If
End Sub
Bala
Simplest solution is to change the DataBinding UpdateMode to OnPropertyChanged.
The default mode is OnValidation, ie: when another control that has CausesValidation = true gets focus.
I also recommend the DataBinding FAQ to learn more about Windows Forms DataBinding.
Thanks a million -
As per your post I inserted this in the load event of the Usercontrol -
" MyCheckBox.DataBindings("Checked").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged "
It worked perfectly.
Thank you once again.
Copyright (c) Marimer LLC