我在尝试将浏览器组件导航到我的组合框选定值时遇到问题 - 当组合框值更改时。
当我像下面那样做时它工作正常(但是当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);
}