加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无法添加列,因为它的CellType属性为空异常

发布时间:2020-12-15 04:22:18 所属栏目:百科 来源:网络整理
导读:我有以下代码的麻烦.当我使用调试器,我得到一个例外,当涉及到以下行: dgvCalls.Columns.Insert(1,msisnnColumn); 我得到一个例外: Column cannot be added because its CellType property is null. 奇怪的是,我为一些其他DataGridView创建了相同的过程,它
我有以下代码的麻烦.当我使用调试器,我得到一个例外,当涉及到以下行:
dgvCalls.Columns.Insert(1,msisnnColumn);

我得到一个例外:

Column cannot be added because its
CellType property is null.

奇怪的是,我为一些其他DataGridView创建了相同的过程,它工作正常.

if (!(dgvCalls.Columns.Contains("DirectionImage")))
                {
                    directionIconColumn = new DataGridViewImageColumn();
                    directionIconColumn.Name = "DirectionImage";
                    directionIconColumn.HeaderText = "";
                    dgvCalls.Columns.Insert(0,directionIconColumn);
                    directionIconColumn.CellTemplate = new DataGridViewImageCell();
                }
                if (!(dgvCalls.Columns.Contains("msisndColumn")))
                {
                    msisnnColumn = new DataGridViewColumn();
                    msisnnColumn.Name = "msisndColumn";
                    msisnnColumn.HeaderText = "Klic";
                    dgvCalls.Columns.Insert(1,msisnnColumn);
                    msisnnColumn.CellTemplate = new DataGridViewTextBoxCell();
                }

有什么建议么?

解决方法

dgvCalls.Columns.Insert(1,msisnnColumn);
msisnnColumn.CellTemplate = new DataGridViewTextBoxCell();

尝试翻转这两行.这可能会做到这一点.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读