I'm developing a small web browser but am struggling with dynamically creating an eventhandler for a dropdown item in the main menu.
I have a SortedList called items containing two values, items.Key is the site name, like "Google", and items.Value is the URL, "www.google.com". Below is the code I use to create the drop down item. I want it to display item.Key, i.e. the site name, but on click I want it to navigate to Item.Value, the URL.
// This code creates the item so that it displays the item.Key value.
// The last line in this foreach loop creates the eventhandler for
//the new item
foreach (DictionaryEntry item in bookmarks)
{
string name = item.Key + "";
if (bookmarksToolStripMenuItem.DropDownItems.ContainsKey(name) != true)
{
bookmarksToolStripMenuItem.DropDownItems.Add(name);
this.bookmarksToolStripMenuItem.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(ClickHandler);
}
}
// This is the event, as far as I am able to do it
// w.Navigate is the method used to navigate to a page
// It accepts a string as input
public void ClickHandler(Object sender, System.EventArgs e)
{
w.Navigate(bookmarksToolStripMenuItem.Text.ToString());
}
Evidently this does not work, as it tries to navigate to the items.Key, or the site name. As of yet I haven't found a solution to this problem.
Does anyone have any ideas?