We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changed regional setting - color format throws exception

Thread ID:





63892 Jul 11,2007 10:06 AM UTC Jul 18,2007 12:33 AM UTC WinForms 4
Tags: GridControl
Jamilah Abdul Rashid
Asked On July 11, 2007 10:06 AM UTC


I am developing an app that needs to be culture independent.

I have a cell with this format:

"TextColor = 255, 255, 255
Font.Size = 12
Interior = Solid; 0, 0, 255"

The format is set to a cell by passing the format(as a string) to cell's GridStyleInfo.ParseString(format). It works ok if select en-US, en-UK, en-AU or sw-KE. However, if i changed the regional setting to ms-MY (Malay-Malaysia), sv-FI and nl-BE it throws exception saying

"255, 255, 255 is not a valid value for Int32".

Is this have something to do with the decimal symbol? Any idea for workaround on this issue?



haneefm [Syncfusion]
Replied On July 11, 2007 09:44 PM UTC

Hi Jamilah,

One way you can do this by handling the Parse and Format events on the GridStyleInfoProperty class to work around this problem. The reason is that if you save a object type out, the grid does not know how to parse it. So, when CellValue is serialized, you also have to include a type so the serialization knows what to do with the object. Here is a little sample with a button handler that mimics what you have.


Best regards,

Jamilah Abdul Rashid
Replied On July 17, 2007 11:07 AM UTC

Hi again,

I think i didn't explain clear enough about the problem.

The issue is, if I have a cell and the CellValueType/CellValue can be any type (int/string), how can i set the format for the TextColor/BackColor? The format that I'm using is - "TextColor = 255, 255, 255".

What I'm currently using is get the cell's GridStyleInfo object and call "ParseString" and send in the format as a string(i.e pass in "TextColor = 255, 255, 255".

It works using that way, however, if I changed the current CultureInfo and refresh the grid, the ParseString function will throw exception saying
"255, 255, 255 is not a valid value for Int32". Why is this happening?

Here are the sample code:

//set the default culture info
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

//create a default format string
GridStyleInfo style = new GridStyleInfo();
style.TextColor = Color.FromArgb(255, 255, 255);
string format = style.ToString(); // format value now is "TextColor = 255, 255, 255"

//apply the format to the GridStyleInfo
GridStyleInfo newStyle = new GridStyleInfo();
string newFormat = newStyle.ToString(); // newFormat value now is "TextColor = White"

//now change the CultureInfo
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ms-MY");
//use the default format again
newStyle.ParseString(format); // <-- this is where it throws exception
string newfred2 = newStyle.ToString();

I also check the InnerException that says:

{System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo)
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)}

How can I fix this. Hope you can help.


haneefm [Syncfusion]
Replied On July 17, 2007 08:52 PM UTC

Hi Jamilah,

Below is a sample that shows you "How to convert the string from style object in a grid?". Please try this and let me know if this helps.

public static Color CurrentParseColor;

public static string ParseString( string s)
int index = s.IndexOf("TextColor");
if (index != -1)
int iend = s.IndexOf('\n',index);
string textColor = s.Substring(index, index + iend+1);
int iequalSign = textColor.IndexOf('=');
string colorstring = textColor.Substring(iequalSign + 1).Replace("\r", "").Replace("\n","") ;

TypeConverter converter = TypeDescriptor.GetConverter(typeof(Color));
object obj = converter.ConvertFromInvariantString(colorstring);
CurrentParseColor = (Color)obj;
s = s.Replace(textColor, "");
return s;

Best regards,

Jamilah Abdul Rashid
Replied On July 18, 2007 12:33 AM UTC

Hi Haneef,

Thanks, this solved my problem. I really appreciate it.

Thanks again.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon