I have problem when trying to navigate my browser component into my combobox selected value – when the combobox value is changed.
It works fine when I’m doing it like below (but then it isnt fired when combobox2 is changed):
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 : )
}
But I see an exception (Unable to cast object of type App1.Foo to type System.String), when It’s like that:
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);
}
I think you should add something like file:/// infront of your path
but there is more you should consider
Links to local files on pages that were retrieved via HTTP(S) are deliberately disabled in Mozilla/Firefox, because they can be a security risk, and have been used in attacks in the past.
http://kb.mozillazine.org/Firefox_:Issues:_Links_to_Local_Pages_Don%27t_Work