Application settings not being saved automatically

  • Thread starter Mihajlo Cvetanović
  • 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?
 
P

Peter Duniho

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
 
M

Mihajlo Cvetanović

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.
 
P

Peter Duniho

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
 
M

Mihajlo Cvetanović

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top