Having spent a lot of yesterday searching on this one I have to give up.
I have a DataGridView linked to a Datatable. One of the columns is an enum and I want that t
Using RosieC's code I still get the exception when the underlying type of an enum is not an Int32. This can be fixed with a minor modification:
public static DataTable Enum2DataTable()
{
DataTable EnumTable = new DataTable();
EnumTable.Columns.Add(new DataColumn("Value", Enum.GetUnderlyingType(typeof(T))));
EnumTable.Columns.Add(new DataColumn("Display", System.Type.GetType("System.String")));
DataRow EnumRow;
foreach (T E in Enum.GetValues(typeof(T)))
{
EnumRow = EnumTable.NewRow();
EnumRow["Value"] = E;
EnumRow["Display"] = E.ToString();
EnumTable.Rows.Add(EnumRow);
}
return EnumTable;
}