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.
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.