I have a seemingly simple problem, I have created a DataTable dynamically and I add rows to it just fine. However I have a column that will have a flag which is an image. I had already imported the two flags(.png images) into the projects resources. However I cant set the DataType for the column as System.Type.Bitmap as DataColumn doesnt support that as can be seen here HERE . I had seen a solution that said I set DataType as below
dataColumn = new DataColumn("Flag");
dataColumn.DataType = System.Type.GetType("System.Byte[]"); //Replacing System.Byte[] with System.Type.Bitmap throws Type Exception
dataTable.Columns.Add(dataColumn);
However that throws an Exception stating that compiler expected Byte[] but got Bitmap.
Here is how I add rows to DataTable
row["Part Number"] = part;
row["Module Name"] = populator.LookUpAValue(moduleSql);
row["Flag"] = Properties.Resources.Yellow_Flag;
row["Location"] = populator.LookUpAValue(nameSql);
dataTable.Rows.Add(row);
Here is my question, which DataType do I save the image column as so when I display to a DataGridView I see the images displayed. Without setting DataType on the DataGridView instead of images being displayed, I get text
System.Drawing.Bitmap
This is the code that worked for me.
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Column1");
dc.DataType = System.Type.GetType("System.Byte[]");
dt.Columns.Add(dc);
DataRow row = dt.NewRow();
var imageConverter = new ImageConverter();
row["Column1"] = imageConverter.ConvertTo(Properties.Resources._1, System.Type.GetType("System.Byte[]"));
dt.Rows.Add(row);
this.dataGridView1.DataSource = dt;