DataGridView中CheckBox列运行时候System.FormatException异常
来源:互联网 发布:单片机烧录器 编辑:程序博客网 时间:2024/05/22 00:11
在DataGridView手动添加了CheckBox列;在窗体Show的时候,遇到一个错误:错误如下:
DataGridView中发生一下异常:System.FormatException:单元格的Formatted值的类型错误.要替换此默认对话框,请处理DataError事件.
点击以后有一对话框错误如下:
DataGridView中发生一下异常:
SystemArgumentException:为DataGridViewCheckBoxCell提供的值的类型错误.
在System.Windows.Forms.DataGridViewCheckBoxCell.set_EditiingCellFormattedValue(Object value)
在System.Windows.Forms.DataGridView.InitializeEditingCellValue (DataGridViewCessStyle&dataGridViewCellStyle,DataGridViewCell&dataGridViewCell)
要替换此默认对话框,请处理DataError事件.
我之前曾经用过CheckBox列,此次和之前的区别是 AllowUserToAddRows=true;我将该属性设置为false,错误没有出现,可以确定该错误与系统自动添加的行及checBox的默认值为null有关。
我在DefaultValuesNeeded事件中增加了默认值,发现错误依旧。
仔细研究发现如下两种解决方法:
其一:在CellFormatting事件中处理
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "AZK")
{
if (e.Value == null)
e.Value = false;
}
}
其二:在在CellFormatting事件中不处理,但DataError事件中处理
{
if (dataGridView1.Rows[e.RowIndex].IsNewRow)
return;
}
Note: DataGridView中几个事件发生的顺序记录如下,以备查寻
在AllowUserToAddRows=true时候的事件发生次序
Form.Show ---> CellFormatting (如果出错,goto DataError),注意这里的NewRow没有触发DefaultValuesNeeded事件。
如果发生其他比如 RowEnter事件
(DefaultValuesNeeded) ---> RowEnter ---> CellClick
(DefaultValuesNeeded) ---> RowsAdded ---> UserAddedRow
DefaultValuesNeeded事件不会发生在 IsNewRow=true的row上
- DataGridView中CheckBox列运行时候System.FormatException异常
- 引发的异常:“System.FormatException"
- DataGridView列中添加CheckBox
- 未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中。
- 未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中
- 在 System.FormatException 中第一次偶然出现的“mscorlib.dll”类型的异常,如何调试呢。
- DataGridView列头checkbox
- 在 DatagridView 中加图像列和 Checkbox 列
- Winform中 DataGridView添加 CheckBox列的问题集锦
- DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- c#DataGridView控件中CheckBox列的使用
- C# 如何为 datagridview 中增加checkbox列
- 在DataGridView加入CheckBox列
- Winform 中DataGridView的checkbox列,当修改checkbox状态时实时获得其状态值
- DataGridView实用攻略-遍历CheckBox列
- 关于datagridview里checkbox列事件
- 带CheckBox列头的DataGridView(一)
- 带CheckBox列头的DataGridView(二)
- JDBC--批量添加数据
- 来自朴实善良的地方
- 整合经营模式之道管理篇——企业发展的本质
- JPA2.0 缓存 之 Cache 注解的使用
- 如何调整Linux内核启动中的驱动初始化顺序
- DataGridView中CheckBox列运行时候System.FormatException异常
- 幸福再给点力吧
- VS2005,VS2008发布网站时生成的自定义命名的固定DLL
- 个人收藏网站
- VC++ ADO 连接 mysql
- JPA @Cache缓存
- 使用ArcCatalog删除某个字段的问题以及解决方法
- android2.3改动翻译版
- JPA 缓存 文章推荐