Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Loading values from the Settings.Settings-file incorrect.

Dear Experts,

I have 4 variables declared in the Settings.Settings-file:

Name = MinVal, Type = string, Value = 3.9
Name = MinRng, Type = string,  Value = 4.4
Name = MaxRng, Type = string, Value = 6.7
Name = MaxVal, Type = string, Value = 8.3

And this I have in the loadevent of my dialog-form called Settings:

        private void Settings_Load(object sender, EventArgs e)
        {
            this.spdMinVal.Text = Properties.Settings.Default.MinVal;
            this.spdMinRng.Text = Properties.Settings.Default.MinRng;
            this.spdMaxRng.Text = Properties.Settings.Default.MaxRng;
            this.spdMaxVal.Text = Properties.Settings.Default.MaxVal;
        }

Open in new window


But in my 4 spinedit-components from DevExpress I get these
values:

39,0 - 44,0 - 67,0 - 83,0

instead of:

3,9 - 4,4 - 6,7 - 8,3

How can I solve this?

Who knows the answer and is willing to help me?

Greetings,

Peter Kiers
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Does that control have a Value() property instead of a Text() one?
Avatar of Peter Kiers

ASKER

Hi,

When I change the default values to "3,9", "4,4" etc.. computers in the US doesn't recognize this. Because you use a period instead of a comma.
so I get: "39.0", "44.0" etc.. And ofcaurse visa versa. When I change the default values to "3.9", "4.4" etc.. I get "39,0", "44,0". Because we use
a comma instead of a period. So what I want to try is to set the default values with a period. But when the form is loaded the code has to check
the currentculure and convert it. I have this line of code from my previous question:

private System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;

Is it posible in this load-event the code read the default-values and the checks the current culture and convert the value
and display it then in the spinedit-components.

        private void Settings_Load(object sender, EventArgs e)
        {
            this.spdMinVal.EditValue = Properties.Settings.Default.MinVal;
            this.spdMinRng.EditValue = Properties.Settings.Default.MinRng;
            this.spdMaxRng.EditValue = Properties.Settings.Default.MaxRng;
            this.spdMaxVal.EditValue = Properties.Settings.Default.MaxVal;
        }

Greetings,

Peter Kiers
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops...Line #23 should be:

                this.spdMaxRng.EditValue = MaxRng.ToString(); // <-- uses the current culture
Thanks Idle_Mind.

Peter
Why do you define your settings as strings when they are numbers? You will end up with the same kind of problems that you would get by defining a numeric field as text in a database.

If you define your settings as numerical values and apply ToString to them, they will automatically convert to the proper format for the environment in which they run.

Name = MinVal, Type = string, Value = 3.9
this.spdMinVal.Text = Properties.Settings.Default.MinVal.ToString()