zoukankan      html  css  js  c++  java
  • 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 后,直接设置列的可见 性

  • 相关阅读:
    linux 常用命令
    git 常见命令
    合并两个有序链表---python
    Code Contract for .NET
    Kruskal最小生成树算法
    逻辑-哲学
    停机问题
    逆向工程
    .net framework
    python 类库
  • 原文地址:https://www.cnblogs.com/wisdo/p/10738095.html
Copyright © 2011-2022 走看看