GrayAreaColor - culture issues?

Posted by: berry on 8 September 2017, 1:49 pm EST

  • Posted 8 September 2017, 1:49 pm EST



    i'm getting the following error when setting the gray area color

    245,250,255 is not a valid value for Int32.

    Code used

    <FONT size=2>

    </FONT><FONT size=1>renderer = <FONT color=#0000ff><FONT color=#0000ff>new</FONT></FONT> FarPoint.Win.Spread.<FONT color=#2b91af><FONT color=#2b91af>EnhancedInterfaceRenderer</FONT></FONT>();</FONT>

    <FONT size=1>renderer.GrayAreaColor = <FONT color=#2b91af size=2><FONT color=#2b91af size=2><FONT color=#2b91af><FONT color=#2b91af>ColorTranslator</FONT></FONT><FONT color=#000000>.FromHtml(</FONT><FONT color=#a31515><FONT color=#a31515>"245,250,255"</FONT></FONT><FONT size=2><FONT color=#000000>)</FONT>

    </FONT></FONT></FONT></FONT><FONT size=2>This happens only when i reset the current culture as</FONT>

    <FONT size=2>

    System.Threading.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Thread</FONT></FONT><FONT size=2>.CurrentThread.CurrentCulture

    = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> System.Globalization.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>CultureInfo</FONT></FONT><FONT size=2>(</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>"fr-FR"</FONT></FONT><FONT size=2>)</FONT>

    <FONT size=2>Please help me get around this</FONT>



    <FONT size=2> 



  • Replied 8 September 2017, 1:49 pm EST


    The FromHtml method uses the current culture settings to parse the string.  In the "fr-FR" culture, the "," character is the decimal separator and the ";" character is the list separate.  Thus, the FromHtml method thinks the string is a floating point number rather that a list for three integers (as you wanted) and will raise an expection because the string is not in a valid format.  When using the "fr-FR" culture, you could use the following code...

        renderer.GrayAreaColor = ColorTranslator.FromHtml("245;250;255")

    If the current culture can vary in your application, then you could dynamically build the string using the current culture's list separator.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels