I have some settings in app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="MA_X" value="true" />
<add key="MA_XF" value="true" />
<add key="MB_X" value="true" />
<add key="MB_XF" value="true" />
<add key="SBE_XGH" value="true" />
<add key="SBE_Y" value="true" />
<add key="SBE_X" value="true" />
<add key="SBV_X" value="true" />
<add key="SBV_XGH" value="true" />
<add key="SBV_XGL" value="true" />
<add key="SBV_YH" value="false" />
<add key="SBV_YL" value="false" />
<add key="SBV_Y" value="true" />
</appSettings>
</configuration>
I give the use some checkboxes to select which attributes are valid. When user clicks save the settings are updated. But when opening exe program again it is initialized to default. How can i add persitence to the AppSettings?
public Settings()
{
InitializeComponent();
var Appsettings= ConfigurationManager.AppSettings;
int i=0;
foreach (var key in Appsettings.AllKeys)
{
i++;
CheckBox cb = new CheckBox();
cb.Checked = Boolean.Parse(Appsettings[key]);
cb.Top = 20*i;
cb.Text = key;
cb.Tag = key;
cbList.Add(cb);
Controls.Add(cb);
}
}
private void btnSave_Click(object sender, EventArgs e)
{
var Appsettings = ConfigurationManager.AppSettings;
foreach (CheckBox cb in cbList)
{
Appsettings[cb.Text] = cb.Checked.ToString();
}
ConfigurationManager.RefreshSection("AppSettings");
}
Also how can i "nest" the settings? I.E for "MA" i would have 2 settings for X and XF.