ブラウザコンポーネントをコンボボックスで選択した値に移動しようとすると、問題が発生します。コンボボックスの値が変更された場合です。
以下のように実行すると正常に動作します(ただし、combobox2が変更されても起動されません)。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(sites.paths[comboBox1.SelectedIndex]);
List<Foo> combo2data = new List<Foo>();
foreach (string s in filePaths)
{
Foo fileInsert = new Foo();
fileInsert.path = s;
fileInsert.name = Path.GetFileName(s);
combo2data.Add(fileInsert);
}
comboBox2.DataSource = combo2data;
comboBox2.ValueMember = "path";
comboBox2.DisplayMember = "name";
this.webBrowser1.Navigate((string)comboBox2.SelectedValue); // THE MOST IMPORTANT LINE : )
}
しかし、次のような場合に例外が発生します(App1.Foo型のオブジェクトをSystem.String型にキャストできません)。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(sites.paths[comboBox1.SelectedIndex]);
List<Foo> combo2data = new List<Foo>();
foreach (string s in filePaths)
{
Foo fileInsert = new Foo();
fileInsert.path = s;
fileInsert.name = Path.GetFileName(s);
combo2data.Add(fileInsert);
}
comboBox2.DataSource = combo2data;
comboBox2.ValueMember = "path";
comboBox2.DisplayMember = "name";
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
this.webBrowser1.Navigate((string)comboBox2.SelectedValue);
}