开发者

Creating Column in DataGridView in C#

开发者 https://www.devze.com 2023-03-08 11:17 出处:网络
I have a problem in creating a datagrid column in c# here is my code. DataGridViewColumn newCol = new DataGridViewColumn();

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 s开发者_如何学Pythonimple 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

0

精彩评论

暂无评论...
验证码 换一张
取 消