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. Newbie: How to find out which menu item has been clicked from a context menu?

Newbie: How to find out which menu item has been clicked from a context menu?

Scheduled Pinned Locked Moved C#
questiondatabasecomtoolshelp
4 Posts 2 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.
  • P Offline
    P Offline
    Phillip Hodges
    wrote on last edited by
    #1

    This is a follow on question from: http://www.codeproject.com/script/comments/forums.asp?forumid=1649&XtraIDs=1649&searchkw=hodges&sd=5%2F16%2F2006&ed=8%2F14%2F2006&select=1619517&df=100&noise=5&mpp=50&fr=319#xx1619517xx I have been able to populate a context menu with data from a database. However I now have the problem of working out which item has been selected from the menu. This is the code that adds the items to the menu: private void addPersonalPhonebookItem(string name, string number) { ToolStripMenuItem personal = ts_phonebook_personal; ToolStripMenuItem personalMenuItem = new ToolStripMenuItem(); personalMenuItem.Name = name; personalMenuItem.Text = name + " (" + number + ")"; personalMenuItem.Click +=new EventHandler(phonebookMenuItem_Click); personalMenuItem.Tag = name + number; personal.DropDown.Items.Add(personalMenuItem); } And this is the EventHandler: void phonebookMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("You Just Clicked: " + e.ToString()); } How do I get the 'name' or 'number' of the clicked item... Thanks again in advance, Phil

    E 1 Reply Last reply
    0
    • P Phillip Hodges

      This is a follow on question from: http://www.codeproject.com/script/comments/forums.asp?forumid=1649&XtraIDs=1649&searchkw=hodges&sd=5%2F16%2F2006&ed=8%2F14%2F2006&select=1619517&df=100&noise=5&mpp=50&fr=319#xx1619517xx I have been able to populate a context menu with data from a database. However I now have the problem of working out which item has been selected from the menu. This is the code that adds the items to the menu: private void addPersonalPhonebookItem(string name, string number) { ToolStripMenuItem personal = ts_phonebook_personal; ToolStripMenuItem personalMenuItem = new ToolStripMenuItem(); personalMenuItem.Name = name; personalMenuItem.Text = name + " (" + number + ")"; personalMenuItem.Click +=new EventHandler(phonebookMenuItem_Click); personalMenuItem.Tag = name + number; personal.DropDown.Items.Add(personalMenuItem); } And this is the EventHandler: void phonebookMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("You Just Clicked: " + e.ToString()); } How do I get the 'name' or 'number' of the clicked item... Thanks again in advance, Phil

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      void phonebookMenuItem_Click(object sender, EventArgs e)
      {
      ToolStripMenuItem mnu = (sender as ToolStripMenuItem);
      MessageBox.Show("You just clicked: " + mnu.Name);
      }

      :rolleyes: (Hmmm, ever wandered what the sender property did?)


      Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

      P 1 Reply Last reply
      0
      • E Ed Poore

        void phonebookMenuItem_Click(object sender, EventArgs e)
        {
        ToolStripMenuItem mnu = (sender as ToolStripMenuItem);
        MessageBox.Show("You just clicked: " + mnu.Name);
        }

        :rolleyes: (Hmmm, ever wandered what the sender property did?)


        Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

        P Offline
        P Offline
        Phillip Hodges
        wrote on last edited by
        #3

        Thanks for the quick reply... Great stuff... Phil:-D

        E 1 Reply Last reply
        0
        • P Phillip Hodges

          Thanks for the quick reply... Great stuff... Phil:-D

          E Offline
          E Offline
          Ed Poore
          wrote on last edited by
          #4

          Not a problem, at least you explained your problem more thouroughly than other people. (And also said thanks which is a nice change :))


          Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

          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