Application settings not being saved automatically

  • Thread starter Thread starter Mihajlo Cvetanović
  • Start date Start date
M

Mihajlo Cvetanović

Hi all,

I created one WinForm window with some controls on it. Then I connected
Text property of each control to one app setting value (User scope).
Automatic loading of these values works fine, but automatic saving
doesn't work. My current solution for saving values is code like this:

Settings.Default.myControl1 = this.myControl1.Text;
Settings.Default.myControl2 = this.myControl2.Text;
....
Settings.Default.myControlN = this.myControlN.Text;
Settings.Default.Save();

This code works, but it offenses my sense of symmetry (not being
automatic). Is there some automatic way to save settings?
 
Mihajlo said:
Hi all,

I created one WinForm window with some controls on it. Then I connected
Text property of each control to one app setting value (User scope).
Automatic loading of these values works fine, but automatic saving
doesn't work. My current solution for saving values is code like this:

Settings.Default.myControl1 = this.myControl1.Text;
Settings.Default.myControl2 = this.myControl2.Text;
....
Settings.Default.myControlN = this.myControlN.Text;
Settings.Default.Save();

This code works, but it offenses my sense of symmetry (not being
automatic). Is there some automatic way to save settings?

Depends on your definition of "automatic". But, with the built-in
Designer-created Settings class, you'll have to call Save() _sometime_.
There's no way around that.

You can certainly call it at some time more convenient than when you are
setting specific values, but you can't avoid calling it altogether.

Pete
 
Depends on your definition of "automatic". But, with the built-in
Designer-created Settings class, you'll have to call Save() _sometime_.
There's no way around that.

I was referring to N repetitive lines. Why do I have to call them, when
I already bound Text properties to application settings? Calling Save
explicitly is actually a good thing.
 
Mihajlo said:
I was referring to N repetitive lines. Why do I have to call them, when
I already bound Text properties to application settings? Calling Save
explicitly is actually a good thing.

You'll have to post a concise-but-complete code example then. I know
it's possible to bind control properties like Text to the settings and
not have to explicitly set the values as you've shown. So if you are
having trouble, it's not because it can't be done. You've just not done
it correctly yet.

And next time you want to ask about setting the values rather than
saving them, I'd recommend you use the word "setting" rather than
"saving" in your subject line. :)

Pete
 
Well somehow things have changed in the mean time. I don't know what I
did (could you explain it to me) but now in the properties of each
control I have value of (DataBindings) > Text set to grayed out text
"(Setting) - myControl". That's new, and now saving settings works like
expected.
 
Back
Top