I have a DataGridView that displays a list of MMS Messages. To differentiate between sent and received, I put a right arrow and left arrow in a column. Our customer loved it, but wants the right arrow to be green for even more clarity, especially in international environments.
I took the right arrow and opened it in Visual Studio 2003 (I am using VS2010 for writing the application). I recolored the icon and it looked great, however when I went to display the containing Control, I get the following error:
The following exception occurred in the DataGridView:
System.ArgumentException: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.ImageConverter.convertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) at System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue) at System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
To replace this default dialog please handle the DataError event.
When I create the DataTable to be populated with the data, I use this on the column that will have the icon
dt.Columns.Add(sDirection);
dt.Columns[sDirection].DataType = typeof(Byte[]);
When I add the data to the rows, I have a method to convert the Icon.
internal static Byte[] ConvertIconToByteArray(Icon pIcon) {
MemoryStream ms = new MemoryStream();
pIcon.Save(ms);
return (ms.GetBuffer());
}
And I add the DataTable to the DataGridView with
grdMMSList.DataSource = dt.DefaultView;
(Method calls removed from the above code for clarity)
I followed through in the debugger, and setting the DefaultView as the DataSource is where the error is getting thrown. I tried placing it in a try/catch block so I could see the Exception, but it doesn't trigger the catch.
Just a few other bits of information: - The icon is stored as a Resource and is called by Properties.Resources.RightArrow - After changing the colors, I just Save the file in VS2003, nothing with a Save As. The file still shows up as an Icon everywhere. - Back in VS2010, the Resource File does have the new color scheme and renders properly there.
Thank you in advance for any help you can provide.