日期:2014-05-18  浏览次数:20743 次

checkBox绑定数据遇到空值怎么办?C#
给checkBox绑定数据,代码如下:
checkBox5.DataBindings.Add("CheckState", bindingSource0, "work");


提示错误——从“System.DBNull”到“System.Windows.Forms.CheckState”的强制转换无效。

------解决方案--------------------
Binding binding = new Binding("CheckState", bindingSource0, "work");
binding.FormattingEnabled = true;
binding.NullValue = CheckState.Indeterminate;
checkBox5.DataBindings.Add(binding);