1

I have a problem in creating a datagrid column in c#

here is my code.

DataGridViewColumn newCol = new DataGridViewColumn();
newCol.HeaderText = txtHeader.Text;
newCol.Width = Convert.ToInt16(cboWidth.Text);
dgWorkArea.Columns.Add(newCol);

On my above code snippet, the error's came when trying to call the fourth (4th) line code. Here is the error.

At least one of the datagridview control's columns has no cell template

Can anyone help me on how can I create a simple column in datagrid.

Dulini Atapattu
  • 2,735
  • 8
  • 33
  • 47
Mark
  • 11
  • 1
  • 2

2 Answers2

4

Try this.

DataGridViewColumn newCol = new DataGridViewTextBoxColumn

I think you wont need any template after this

You can also go for check box type column or any other type. All available options are listed here

Haris Hasan
  • 29,856
  • 10
  • 92
  • 122
0

http://msdn.microsoft.com/ru-ru/library/system.windows.forms.datagridviewcolumn

there are different type of columns: DataGridViewTextBoxColumn, DataGridViewLinkColumn, etc.

You need somethis like this:

DataGridViewColumn newCol = new DataGridViewTextBoxColumn();

in first row

ForeverSmiling
  • 111
  • 3
  • 10