User settings are not saved (Settings.Default.Save ();)

In the project properties, I created such a setting

NumberOfUsers int User 10

Columns are the name, type, scope, and value.

Then there is a ComboBox where the user can set "NumberOfUsers". There is a SelectedIndexChanged event in this combo where I save changes when the user changes the combo value. Here is the code:

Settings.Default.NumberOfUsers = combo1.SelectedIndex;
Settings.Default.Save();

A form with this combo is called from the parent as frm.ShowDialog();, and in the constructor of the child form I try to set the combined selected index based on the settings record

combo1.SelectedIndex = Settings.Default.NumberOfUsers;

However, this does NOT work, that is, the combo does not pull the value from the parameter, but by default it is 0 as the selected index.

Does anyone know where I am going wrong?

+3
3

, . , VS . .
AppData ( ?) :

AppData\[Local_or_Roaming]\YourCompanyName\yourprogram.exe_Url _ [...]\1.0.0.0\user.config

s.g. , . , .

, . , dev- .

+4

, :

Properties.Settings.Default.NumberOfUsers = combo1.SelectedIndex;
Properties.Settings.Default.Save();
combo1.SelectedIndex = Properties.Settings.Default.NumberOfUsers;
0

Do you enter a new value for NumberOfUsers in a ComboBox or select it from the drop-down list?
If you enter the value SelectedIndex, this will not change, so no event will be fired.

In addition, the ComboBox is populated with values ​​from 0 to 10, or you have code to handle ArgumentOutOfRangeExceptions

0
source

Source: https://habr.com/ru/post/1759652/


All Articles