Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Removing Context Menu Items

Removing Context Menu Items

Scheduled Pinned Locked Moved C#
databasetutorialquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MCSD Gandalf
    wrote on last edited by
    #1

    I have an Windows app that allows users to save "bookmarks", pages they have been, 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. 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) -- modified at 8:09 Tuesday 2nd May, 2006

    M 1 Reply Last reply
    0
    • M MCSD Gandalf

      I have an Windows app that allows users to save "bookmarks", pages they have been, 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. 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) -- modified at 8:09 Tuesday 2nd May, 2006

      M Offline
      M Offline
      MCSD Gandalf
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups