WinForms (C #) Data Binding Object to Checkbox.Checked Property

I am writing a WinForms application and am trying to bind a boolean property on a .NET object to the Check Check Check property. I successfully create the binding, but when I change the value of the source property from false to true (I have a button that toggles it), the check checked checked property does not reflect this change.

if (chkPreRun.DataBindings["Checked"] == null) { Debug.WriteLine("Adding chkPreRun databinding"); Binding _binding = chkPreRun.DataBindings.Add("Checked", NwmConfig, "PreRun") // Added this just to ensure that these were being set properly _binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged; _binding.ControlUpdateMode = ControlUpdateMode.OnPropertyChanged; } 

I can successfully bind the text property to a TextBox value, for example. I'm not sure what I am missing when binding to the Checked property.

+4
source share
1 answer

For this to work, the source must either have a PreRunChanged event ( EventHandler ) that is fired, or it must implement INotifyPropertyChanged (including for this property). Or, as an edge case, it should have a custom PropertyDescriptor implementation that supports notification (but this is very rare).

Does your code have PreRunChanged ? Does it rise at the appropriate time?

(the user interface does not check for changes, it knows about changes through notification events)

+7
source

Source: https://habr.com/ru/post/1309917/


All Articles