1

I am trying to bind a checkbox to a custom object boolean property as follows:

chkTableIsReadonly.DataBindings.Add(New Binding("Checked", objectBindingSource, "ApplyforVisa", True, DataSourceUpdateMode.OnPropertyChanged, False))

The custom class supports the INotifyPropertyChanged interface.

Everything works find when I initially bind the checkbox to a new object:

objectBindingSource.Datasource = new objectToBindTo

Here is the odd part:

  1. If I check the box, the property Set gets called and the INotifyPropertyChanged event gets called and everyone is happy.
  2. If I uncheck the same box, the property Set doesn't get called, the INotifyPropertyChanged event never gets called and (the worse part), I cannot navigate to another record.

I have tried capturing the CheckedChanged event to set the object.ApplyForVisa property manually, but no success. The property Set gets called and the INotifyPropertyChanged event gets called, but I am still locked on control and can't navigate.

I have tried calling bindingsource.endedit in the CheckedChanged event, no success.

It only matters if I uncheck the box. The checkbox is two-state - true or false.

All of my other bindings work just fine - text boxes, combo boxes, datagrid. Just not checkbox.

My only thought is that is seems to act like a binding source data error, but no error is thrown. If I add the data error event handler for the binding source, it never gets called.

4

1 回答 1

4

假设该ApplyForVisa属性是一个布尔值,您可以通过将formattingEnabled参数设置为BindingFalse 来解决这个问题。

chkTableIsReadonly.DataBindings.Add( _
    New Binding("Checked", objectBindingSource, "ApplyforVisa", _
                False, DataSourceUpdateMode.OnPropertyChanged, False))
于 2012-07-26T15:42:35.347 回答