how to add column dynamically in datagridview using c#
+2
A:
If it's like any of the other .Net grid controls:
YourDataGridView.Columns.Add(New DataGridViewColumn());
DaRKoN_
2010-03-04 07:06:10
Columns.Add can throw an exception if the CellType property of your DataGridViewColumn is null. I believe it's better to set the DataGridViewColumn's CellTemplate before adding it (CellType is the runtime type of CellTemplate), or to use a class that inherits from DataGridViewColumn for which CellTemplate is already set appropriately.
Tim Goodman
2010-03-04 07:38:55
@Tim Goodman - I'd agree, my example is just to show basically how it can be done. An actual implementation would be a bit more involved.
DaRKoN_
2010-03-04 08:42:17
+2
A:
For example:
DataGridViewColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "Hi there";
int colIndex = grid.Columns.Add(col);
Marc Gravell
2010-03-04 07:06:59
+2
A:
These links shall help you out doing more than just adding columns:
101 Ways to Manipulate the DataGridView Control (page 1)
101 Ways to Manipulate the DataGridView Control (page 2)
Will Marcouiller
2010-03-04 07:14:03