Ogglas
Ogglas

Reputation: 70176

System.Window.Forms.CheckBox databinding won't get hit

I have a problem with System.Window.Forms.CheckBox databinding. I generate a checkbox and then map it's value to a property on a BindingSource via

Checkbox → Properties → DataBindings → Checked → BindingSource - PropertyValue

I then have a CheckedChanged event that get's triggered when i click on the checkbox. However on click the BindingSource property is not updated. Because of this I have to use checkbox Design -> Name to get the value of the checkbox. Should the binding be done in another way? I can map strings this way with no problem but for some reason a checkbox bool seems harder to map.

Upvotes: 2

Views: 264

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125277

When you setup data-binding, the default value for Data Source Update Mode is OnValidation which means Data source is updated when the control property is validated. So in the current state if you move the focus to another control the data-binding will update the data source property.

If you want data source update whenever the value of the control property changes, you should change the setting to OnPropertyChanged.

You can change the setting using designer this way:

  1. Select the control and in property grid, expand (DataBindings) and click ... in from of (Advanced) to open Formatting and Advanced Binding.

  2. In the window, from the left Property list, select the property which you want to perform advanced setting for it.

  3. At right pane, from Data Source Update Mode select OnPropertyChanged. To learn more about other available values, take a look at DataSourceUpdateMode documentations.

Upvotes: 4

Related Questions