I need a way in which I can define the column type at run-time.
Here is my code:
foreach (DataGridViewColumn column in this.dataGrid.Columns)
{
???
/
I assume you mean when you create the DataGridView. In that case you can define it in a DataTable and hook it up to the dgv's Datasource:
For example:
var columns = new List>();
columns.Add(new Tuple("Name", "System.String"));
columns.Add(new Tuple("Selected", "System.Boolean"));
columns.Add(new Tuple("Id", "System.Int32"));
var table = new DataTable();
columns.ForEach(c => table.Columns.Add(new DataColumn(c.Item1) { DataType = Type.GetType(c.Item2) }));
var dgv = new DataGridView();
dgv.DataSource = table;