0

I am getting this error when dynamically binding my controls onto the dataSource. (Most answers respond to when using parameters : like this one Object cannot be cast from DBNull to other types ). Can we expand for when binding controls?

Chagbert
  • 722
  • 7
  • 16

1 Answers1

0

Just tried the extensions of the "DataBindings.Add" method: therefore this code:

            this.chkDispensed.DataBindings.Add("Checked", DT_items, "dispensedItem_bol");
            this.chkDirectionsAuto.DataBindings.Add("Checked", DT_items, "directionsAuto_bol");

.. Changes to

            bool myDefBool = false;
            this.chkDispensed.DataBindings.Add("Checked", DT_items, "dispensedItem_bol", true, DataSourceUpdateMode.OnPropertyChanged, myDefBool);
            this.chkDirectionsAuto.DataBindings.Add("Checked", DT_items, "directionsAuto_bol", true, DataSourceUpdateMode.OnPropertyChanged, myDefBool);

This takes care of the NULL values from the database. I suppose it MUST be done for ALL controls, any type. Thank you.

Chagbert
  • 722
  • 7
  • 16