Column cannot be added because its CellType property is null exception

Posted by niko on Stack Overflow See other posts from Stack Overflow or by niko
Published on 2008-11-06T16:38:39Z Indexed on 2010/03/24 7:53 UTC
Read the original article Hit count: 731

Filed under:
|

Hi,

I have trouble with the following piece of code. When I go through with the debugger I get an exception when it comes to the following line:

dgvCalls.Columns.Insert(1, msisnnColumn);

I get an exception:

Column cannot be added because its CellType property is null.

Oddly, I created the same procedure for some other DataGridViews and it worked fine.

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();
                }

Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about datagridview