Reputation: 300
I got an Application with a DataGridView. When I'm adding a new DataGridViewColumn to it, the whole Window is white and no DataGridView appears. I searched for this problem but found nothing.
columns
is an Array of Strings
foreach (String strings in columns) {
DataGridViewColumn column = new DataGridViewColumn();
column.Name = strings;
column.HeaderText = strings;
grid.Columns.Add(column);
}
But when I'm adding a new Column without instancing a new DataGridViewColumn, the DataGridView appears in the Window:
foreach (String strings in columns) {
grid.Columns.Add(strings, strings);
}
The problem is that I have to have these DataGridViewColumns in my App. What can I do?
Upvotes: 1
Views: 1702
Reputation: 81620
You should be getting an error, but in any case, you have to specify the column type:
var column = new DataGridViewTextBoxColumn();
column.Name = strings;
column.HeaderText = strings;
grid.Columns.Add(column);
Upvotes: 2