Control Binding of a bool isn't updating
-
hi, I want to bind a bool property of my class to the "Enabled" property of a control, but when I change my bool property, the enabled state of my control isn't changing, here an example
// bool Property private bool boolValue = false; public bool BoolValue { get { return boolValue; } set { boolValue = value; } } // binding button1.DataBindings.Add("Enabled", this, "BoolValue", false, DataSourceUpdateMode.OnPropertyChanged); // later in code BoolValue = true; // enabled state of my control isn't changing
How can I solve this problem? Regards, timm -
hi, I want to bind a bool property of my class to the "Enabled" property of a control, but when I change my bool property, the enabled state of my control isn't changing, here an example
// bool Property private bool boolValue = false; public bool BoolValue { get { return boolValue; } set { boolValue = value; } } // binding button1.DataBindings.Add("Enabled", this, "BoolValue", false, DataSourceUpdateMode.OnPropertyChanged); // later in code BoolValue = true; // enabled state of my control isn't changing
How can I solve this problem? Regards, timmThe "DataSourceUpdateMode.OnPropertyChanged" is a flag that sends button1's "Enabled" value to the current record's "BoolValue" field. It does not tell the datasource to send updates to the control. What you need to do is force the binding context of the button to update it's index. This will cause: button1 to read the changed value.
The mind is like a parachute. It doesn’t work unless it’s open.
-
hi, I want to bind a bool property of my class to the "Enabled" property of a control, but when I change my bool property, the enabled state of my control isn't changing, here an example
// bool Property private bool boolValue = false; public bool BoolValue { get { return boolValue; } set { boolValue = value; } } // binding button1.DataBindings.Add("Enabled", this, "BoolValue", false, DataSourceUpdateMode.OnPropertyChanged); // later in code BoolValue = true; // enabled state of my control isn't changing
How can I solve this problem? Regards, timmYou'll need to implement the OnBoolValueChanged event or OnPropertyChanged after the boolValue = value assignment. http://krisvandermotten.wordpress.com/2006/10/19/properties-with-property-changed-event/[^] http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/1e742062-bf41-48cf-bd2f-54bdc9c5b78d[^] Personally I prefer the OnXXXChanged because I'd rather not write a gigantic switch in the OnPropertyChanged handler.