WinForm Column cannot be added because its CellType property is null.
Posted wisdo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WinForm Column cannot be added because its CellType property is null.相关的知识,希望对你有一定的参考价值。
在Winform DatatGridView 控件中绑定了一个模型的属性,结果在生成窗口时,发生错误,异常信息如下 :
Column cannot be added because its CellType property is null.
at System.Windows.Forms.DataGridView.OnAddingColumn(DataGridViewColumn dataGridViewColumn)
at System.Windows.Forms.DataGridViewColumnCollection.Add(DataGridViewColumn dataGridViewColumn)
at System.Windows.Forms.DataGridView.CorrectColumnFrozenStates(DataGridViewColumn[] dataGridViewColumns)
at System.Windows.Forms.DataGridView.OnAddingColumns(DataGridViewColumn[] dataGridViewColumns)
at System.Windows.Forms.DataGridViewColumnCollection.AddRange(DataGridViewColumn[] dataGridViewColumns)
找了好半天才找出问题的原因,绑定的属性在数据库表中不存在的列名
解决方案如下 :
1. 绑定的字段一定要与数据库表中的列的字段名相同
2. 如果是模型,这个模型的属性字段在数据库中没有,那就不用把属性写在datagridView 的列中,在设置datasource 后,直接设置列的可见 性
以上是关于WinForm Column cannot be added because its CellType property is null.的主要内容,如果未能解决你的问题,请参考以下文章
异常:java.sql.SQLIntegrityConstraintViolationException: Column 'category' cannot be null
异常:java.sql.SQLIntegrityConstraintViolationException: Column 'category' cannot be null
django-registration (1048, “Column 'last_login' cannot be null”)
mysql 设置了默认值了为啥还是会报column cannot be null
完整性约束违规:1048 Column 'user_id' cannot be null 分配角色时发生错误(Laravel 5.3)
170PostgreSQL 10字段类型从字符串修改成整型,报错column cannot be cast automatically to type integer