In my program, the user can save the settings with a button. The store works. Loading the settings does not work quite right. I have a problem when loading the rule. I have several rules as a list. I dont know how to specify the index. Can anybody help me please?
Methods to save/load the settings:
private void SaveUserConfigButton_Click(object sender, EventArgs e)
{
var userConfig = new UserConfig();
userConfig.RandomPopulation = (int)_probability;
userConfig.Rule = _gameOfLife.NextGenerationRule.RuleName;
userConfig.Speed = _timer.Interval;
userConfig.UseBoundary = _gameOfLife.UseBoundary;
SaveUserConfig(userConfig);
}
private void MainForm_Load(object sender, EventArgs e)
{
var userConfig = LoadUserConfig(_path);
InputRandomPopulationNumbericUpDown.Value = userConfig.RandomPopulation;
SelectRulesComboBox.SelectedItem = _rules[5]; // <-- here is the problem
SpeedTrackBar.Value = userConfig.Speed;
BoundaryCheckBox.Checked = userConfig.UseBoundary;
}
My english is not so good, I hope it is understandable.
_rules? The line where you say it's a problem is the first time you mention it.SelectRulesComboBox.SelectedIndexrather thanSelectedItem?