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'm not 100% certain I understand you question, but you can specify the column type when you create the column:
foreach (var definition in columnDefinitions) // Some list of what the column types are
{
var columnSpec = new DataColumn
{
DataType = definition.Type, // This is of type System.Type
ColumnName = defintion.Name // This is of type string
};
this.dataGrid.Columns.Add(columnSpec);
}
If you need to change the type once it's been created - you can't do that. The best you can do is delete the columns and recreate them with the new types.