私のプログラムでは、ボタンを使って設定を保存することができます。店舗は機能します。設定をロードしても正しく動作しません。ルールを読み込む際に問題があります。私はリストとしていくつかのルールを持っています。私はインデックスを指定する方法を知らない。誰でも助けてくれますか?C#winフォームでXMLファイルをロードする
方法は、保存/設定をロードします
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;
}
私の英語はあまりよくないですが、私はそれが理解を願っています。
SaveUserConfigメソッドとLoadUserConfigメソッドを表示できますか?さらに、_rules [5]を使用してComboBox.Selected項目をロードし、UserConfigからプロパティをロードしないようにしてください。 –
'_rules'とは何ですか?あなたがそれが問題だと言う行は、あなたがそれに言及した最初のことです。 – Bridge
'SelectedItem'ではなく' SelectRulesComboBox.SelectedIndex'を意味していませんか? – Bridge