G
Guest
I have an Windows app that allows users to save "bookmarks", on pages they
have been to, and then navigate back to them. That all works. In addition, we
have restricted them to 15 bookmarks, and if they select a 16th, the first
one in is popped out. I am attaching a Context Menu to a button on the
toolbar.
Now they would like to be able to delete an individual bookmark. I have the
code working to dynamically add the bookmarked pages, to a sub-menu item for
deletes. I even have the code working to delete the item from that MeunItems
collection. When I check the count of that collection, it is correct, and
when I click my code to add another bookmark, the old ones appear, and the
one I deleted is gone. HOWEVER, when I go through the delete code, and then
click on the button, none of the entries appear. The sub-menu for the deletes
is blank. Here's the code:
Load the Menu Items, both in the Main menu and the Delete Bookmarks
private void button1_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < 6; i++)
{
MenuItem myMenuItem =
mainToolBar.Buttons[0].DropDownMenu.MenuItems.Add("Added Item " + i);
this.mainToolBar.Buttons[0].DropDownMenu.MenuItems[myMenuItem.Index].Click
+= new System.EventHandler(AnotherMenuTestMethod);
deleteBookmarkMenuItem.MenuItems.Add(myMenuItem.CloneMenu());
deleteBookmarkMenuItem.MenuItems[deleteBookmarkMenuItem.MenuItems.Count
-1].Click -= new System.EventHandler(AnotherMenuTestMethod);
deleteBookmarkMenuItem.MenuItems[deleteBookmarkMenuItem.MenuItems.Count
-1].Click += new System.EventHandler(DeleteMenuTestMethod);
}
}
Here I'm trying to delete a specific one (just to see how to do it)
public void DeleteMenuTestMethod(object sender, System.EventArgs e)
{
MenuItem myMenuItem = (MenuItem)sender;
deleteBookmarkMenuItem.MenuItems.RemoveAt(3);
MessageBox.Show(deleteBookmarkMenuItem.MenuItems.Count.ToString());
}
As I mentioned the count is right, but when I click on the button, NOTHING
appears in the Delete Items.
By the way the 'deleteBookMarkMenuItem' variable is a global one for the
form.
I'm obviously missing something, anyone spot it?
THANKS!
WhiteWizard (aka Gandalf)
have been to, and then navigate back to them. That all works. In addition, we
have restricted them to 15 bookmarks, and if they select a 16th, the first
one in is popped out. I am attaching a Context Menu to a button on the
toolbar.
Now they would like to be able to delete an individual bookmark. I have the
code working to dynamically add the bookmarked pages, to a sub-menu item for
deletes. I even have the code working to delete the item from that MeunItems
collection. When I check the count of that collection, it is correct, and
when I click my code to add another bookmark, the old ones appear, and the
one I deleted is gone. HOWEVER, when I go through the delete code, and then
click on the button, none of the entries appear. The sub-menu for the deletes
is blank. Here's the code:
Load the Menu Items, both in the Main menu and the Delete Bookmarks
private void button1_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < 6; i++)
{
MenuItem myMenuItem =
mainToolBar.Buttons[0].DropDownMenu.MenuItems.Add("Added Item " + i);
this.mainToolBar.Buttons[0].DropDownMenu.MenuItems[myMenuItem.Index].Click
+= new System.EventHandler(AnotherMenuTestMethod);
deleteBookmarkMenuItem.MenuItems.Add(myMenuItem.CloneMenu());
deleteBookmarkMenuItem.MenuItems[deleteBookmarkMenuItem.MenuItems.Count
-1].Click -= new System.EventHandler(AnotherMenuTestMethod);
deleteBookmarkMenuItem.MenuItems[deleteBookmarkMenuItem.MenuItems.Count
-1].Click += new System.EventHandler(DeleteMenuTestMethod);
}
}
Here I'm trying to delete a specific one (just to see how to do it)
public void DeleteMenuTestMethod(object sender, System.EventArgs e)
{
MenuItem myMenuItem = (MenuItem)sender;
deleteBookmarkMenuItem.MenuItems.RemoveAt(3);
MessageBox.Show(deleteBookmarkMenuItem.MenuItems.Count.ToString());
}
As I mentioned the count is right, but when I click on the button, NOTHING
appears in the Delete Items.
By the way the 'deleteBookMarkMenuItem' variable is a global one for the
form.
I'm obviously missing something, anyone spot it?
THANKS!
WhiteWizard (aka Gandalf)