Hi!
I have a DataTable that i assign to a datagrid control. Since the structure of the DataTable is built dynamically I don't build any table/column styles for my grid, but access afterwards the automatically built column styles.
Now my problem: In my DataTable, there is a column of the type byte array (length 16 - it is a GUID, coming from an Oracle db). By default, the datagrid can't display it, so i read "byte[] array" instead of my guid.
So I have written a little GuidFormatter class as attached.
After assigning my table to the grid i step through all columns and locate my byte[] column. I set the FormatInfo property to an instance of my GuidFormatter class. But nothing happens. The Format and GetFormat methods are never called, even after calling the Refresh method of the datagrid. Why???
Thank you in advance.
Regards,
Daniel
I have a DataTable that i assign to a datagrid control. Since the structure of the DataTable is built dynamically I don't build any table/column styles for my grid, but access afterwards the automatically built column styles.
Now my problem: In my DataTable, there is a column of the type byte array (length 16 - it is a GUID, coming from an Oracle db). By default, the datagrid can't display it, so i read "byte[] array" instead of my guid.
So I have written a little GuidFormatter class as attached.
Code:
public class GuidFormatter: IFormatProvider, ICustomFormatter
{
public GuidFormatter() {}
public object GetFormat(Type formatType)
{
return formatType == typeof(ICustomFormatter) ? this : null;
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
if (format == null)
return String.Format(formatProvider, "{0}", arg);
string s = (new Guid((byte[])arg)).ToString();
return s;
}
}
After assigning my table to the grid i step through all columns and locate my byte[] column. I set the FormatInfo property to an instance of my GuidFormatter class. But nothing happens. The Format and GetFormat methods are never called, even after calling the Refresh method of the datagrid. Why???
Thank you in advance.
Regards,
Daniel