我有以下代码的麻烦.当我使用调试器,我得到一个例外,当涉及到以下行:
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();
尝试翻转这两行.这可能会做到这一点.