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.
Unfortunately, activation email could not send to your email. Please try again.

Changed regional setting - color format throws exception

Thread ID:

Created:

Updated:

Platform:

Replies:

63892 Jul 11,2007 06:06 AM Jul 17,2007 08:33 PM Windows Forms 4
loading
Tags: GridControl
Jamilah Abdul Rashid
Asked On July 11, 2007 06:06 AM

Hi,

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?

Thanks,
Jamilah

RegionalTest.zip

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

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.

GC_FormulaParse.zip

Best regards,
Haneef

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

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();
newStyle.ParseString(format);
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.

Thanks,
Jamilah

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

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.
ModifiedRegionalTest.zip

[c#]
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,
Haneef

Jamilah Abdul Rashid
Replied On July 17, 2007 08:33 PM

Hi Haneef,

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

Thanks again.

Cheers,
Jamilah

CONFIRMATION

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.

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.

;