I have this rater simple application, where I use settings. For that, I have created my own Properties settings file. So far so good. That works all well. The settings are there and I can use them.
I am trying to be able to change these settings at runtime.
From the looks of it, that also works quite well. Looking at the user.config
for the application under the user running the application, settings ARE being saved.
However, the next time I load the application, it seems to ignore the saved settings and use the default ones.
Once again I can change the the settings and save them, with the same result.
The user.config
is being updated, but the old default settings are always the once being shown on load.
I load the settings into a ListView. Change the values from there, and then loops through the ListView, saving the settings again.
This is where I load the settings in the ListView: (Properties.Main
is the settings I have created)
private void Settings_Load(object sender, EventArgs e)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
textBox1.Text = config.FilePath;
foreach (SettingsProperty Setting in Properties.Main.Default.Properties)
{
ListViewItem settingitem = new ListViewItem();
settingitem.Text = Setting.Name.ToString();
settingitem.SubItems.Add(Setting.DefaultValue.ToString());
listView1.Items.Add(settingitem);
}
listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
And this is where I save the settings.
private void button1_Click(object sender, EventArgs e)
{
try
{
foreach (ListViewItem setting in listView1.Items)
{
Properties.Main.Default[setting.Text] = setting.SubItems[1].Text; ;
Properties.Main.Default.Save();
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
From what I can see, the settings are being saved as expected in the user.config
file, but it is not the one being loaded the next time.
I am getting the impression, that there is something I need to do, in order for the application not to load the default settings each time.
Any ideas?