2
votes

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.

1

1 Answers

1
votes

I would not edit the images this way. If you want a valid set of arrows that are all supported for addition into a DataGridView, so to the directory

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033

here you will find a .zip file. Unzip it.

Then you will find varios subdirectories with loads of MS icon and images etc. Navigate to

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033
    \VS2010ImageLibrary\VS2010ImageLibrary\Objects\png_format\WinVista

here you will find all different kinds of arrows in all different colours. My advice is use these, not your bitmap edits to existing files.

I hope this helps.