Reputation: 175
I am attempting to bind to a checkbox that has the ThreeState propety set to True. We want to be able to return a null if the CheckState is indeterminate without writing an event handler for each checkbox. This particular form has more than 20 checkboxes on it.
I have attempted to bind to the CheckState, but the indeterminate state does not return the null and locks the form up. Binding to the checked property returns a True when the checkbox is in the indeterminate state. Also, we are binding to class object properties, not to datatables.
The team has two possible solutions that both have their drawbacks: One is to create an additional property in the class for each boolean property that reads the CheckState and then sets the boolean property to null, true, or false accordingly. Painful to add all of these properties to all of the classes that have boolean fields that are not required fields.
Second one is to create a custom control control that inherits the checkbox control and adds a new property that we can bind to with the boolean property of the class. Custom controls have their own problems as most know.
My questions are: What am I overlooking? Is there a better way to implement this through databinding? What other methods have others used?
Upvotes: 1
Views: 3758
Reputation: 175
Thanks to Chris F for mentioning the nullable (of Boolean) data type.
By setting the property datatype to Nullable(of Boolean) and THEN setting the binding to the CheckState instead of checked causes everything to work properly. The values being sent to the database correspond to the proper settings. Intermediate sets the value to Nothing (Null in the database), Checked sets it to True, unchecked sets it to False.
Upvotes: 5