0

How can I store the user's choice permanently in c# winform. I wrote this code to fetch the setting:

string my_data_to_do = (string)Settings.Default["MyDataToDo"];

And to save the user's setting I wrote:

if (checkBox3.Checked)
{
   Settings.Default["MyDataToDo"] = "Tasks In Hand";
}
else
{
   Settings.Default["MyDataToDo"] = "Nothing To Do";
}

This is showing the saved data but only until I exit my application. When I exit and start my program again, all these settings gets automatically removed, and the default data comes, which I saved in Settings.settings file.

Can anyone please help me in this?

Omar
  • 16,329
  • 10
  • 48
  • 66
user1547766
  • 465
  • 1
  • 8
  • 17
  • possible duplicate of [What is the best way to store user settings for a .NET application?](http://stackoverflow.com/questions/26369/what-is-the-best-way-to-store-user-settings-for-a-net-application) – Omar Mar 17 '13 at 10:29
  • I recently tried **Settings.Default.Save()** and **Settings.Default.Upgrade()**, but none of them actually worked. – user1547766 Mar 17 '13 at 11:41
  • Make sure it is "User" Setting, and also you can directly reference it as Setting.Default.MyDataToDo="Some String"; no need to use it as a dict or JSON like data structure. – David Mar 17 '13 at 13:47

1 Answers1

5

It's hard to tell if you're doing it from just the code exert you've posted, but after setting the setting like that you will need to call Settings.Default.Save() to have it persist beyond the application closing.

ZW1404
  • 78
  • 4