【发布时间】:2020-09-15 21:21:09
【问题描述】:
将控件动态绑定到数据源时出现此错误。 (大多数答案在使用参数时都会做出响应:就像这个Object cannot be cast from DBNull to other types)。 绑定控件时可以扩展吗?
【问题讨论】:
将控件动态绑定到数据源时出现此错误。 (大多数答案在使用参数时都会做出响应:就像这个Object cannot be cast from DBNull to other types)。 绑定控件时可以扩展吗?
【问题讨论】:
刚刚尝试了“DataBindings.Add”方法的扩展:因此这段代码:
this.chkDispensed.DataBindings.Add("Checked", DT_items, "dispensedItem_bol");
this.chkDirectionsAuto.DataBindings.Add("Checked", DT_items, "directionsAuto_bol");
.. 更改
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);
这会处理数据库中的 NULL 值。我想它必须为所有控件完成,任何类型。谢谢。
【讨论】: