• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

ContextMenuStrip menuItem.Name is always ""


Active member
Aug 23, 2012
Programming Experience
My menu code fires the menu click event but the menuItem.Name is always ""

Obviously my code isn't setup right.

Thanks for any help.

            ContextMenuStrip menuStrip = new ContextMenuStrip();
            ToolStripMenuItem menuItem = new ToolStripMenuItem();
            menuItem.Click += new EventHandler(menuItem_Click);
            panelMenu.ContextMenuStrip = menuStrip;

        void menuItem_Click(object sender, EventArgs e)
            ToolStripItem menuItem = (ToolStripItem)sender;
            if (menuItem.Name == "1111")



C# Forum Moderator
Staff member
Apr 23, 2011
Sydney, Australia
Programming Experience
Have you read the relevant documentation? It would appear not. If you had read the appropriate documentation, or just taken notice of Intellisense as you typed, then you'd know that that Add method you're calling is described thusly:
Adds a ToolStripItem that displays the specified text to the collection.
Think about, for instance, a TextBox. How do you get the text it displays? Is it via the Name property?

When you encounter an issue, ALWAYS read the relevant documentation first. There's a Help menu right there in VS. Read the documentation for any types and members that you're using and make sure that they work the way you think they work. You'll find that you can then answer many of your questions yourself. I speak from personal experience. Forums are great and I use them myself, but never before reading the appropriate information first.
Top Bottom