Finally gave up using DynamicObject. Created a DataTable instead:
public static DataTable CreateTable(IEnumerable<RowValidator> model)
{
var Good = imageToByteArray(Properties.Resources.Check16);
var Bad = imageToByteArray(Properties.Resources.Block16);
var table = new System.Data.DataTable();
table.Columns.Add(new DataColumn("Pass", System.Type.GetType("System.Byte[]")));
foreach (var column in model.First().ValueValidators)
table.Columns.Add(new DataColumn(column.Key));
foreach (var validator in model)
{
var row = table.NewRow();
row["Pass"] = validator.IsValid ? Good : Bad;
foreach (var column in validator.ValueValidators)
row[column.Key] = column.Value.Value;
table.Rows.Add(row);
}
return table;
}
private static byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
Then in the form do:
private void FormLoad(object sender, System.EventArgs e)
{
if (_table != null)
{
_bindingSource.DataSource = _table;
dataGrid.DataSource = _bindingSource;
return;
}
}