Removing Context Menu Items

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)
 
G

Guest

As it turns out, it appears this is a "bug" in .NET 2003, and has been fixed
in 2005. I took the code as is into VS 2005 and it works fine. As we are
moving there in the next month or so, I guess I'll just wait to finish this
then.

WhiteWizard (aka Gandalf)
MCSD.NET, MCAD, MCT
 
L

Larry Lard

WhiteWizard said:
As it turns out, it appears this is a "bug" in .NET 2003, and has been fixed
in 2005. I took the code as is into VS 2005 and it works fine. As we are
moving there in the next month or so, I guess I'll just wait to finish this
then.

I thought it might be that. My investigation had got as far as noticing
that deleteBookmarkMenuItem's .Handle was changing, suggesting the
win32 menu was being recreated on a whim, but I couldn't pin it down
any further.

Is there an online reference to this bug?
 
G

Guest

I did not find an online reference to the bug. I had just decided to see if
I got the same reaction in 2005, and turns out it runs fine there.

Thanks for trying.

WhiteWizard (aka Gandalf)
MCSD.NET, MCAD, MCT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top