How do I capture the information of the Toolstripmenuitem that was clicked

How do I capture the Toolstripmenuitem that was clicked.
I have a windows form developed in VS 2005, which has a menustrip which has many toolstripmenuitems, which in turn have child  toolstripmenuitems.

The Toolstripmenuitems are added to the menustrip at runtime dynamically from an xml file.
How do I detect which item within the menustrip was clicked
I used this as my reference to bind the menustrip to the xml file

http://www.codeproject.com/useritems/XML_Driven_Menu_Strip.asp?df=100&forumid=408426&exp=0&select=1993718
LVL 1
countrymeisterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

so3Commented:
Run the CreateEvents method after the menustrip is poulated from xml, and when you press a toolstripmenuitem in the event child_item_DropDownItemClicked you will have the toolstripmenuitem in e.clickeditem

 private void CreateEvents(MenuStrip menu, ToolStripMenuItem item)
        {
            if (item == null)
            {
                foreach (ToolStripMenuItem child_item in menu.Items)
                {
                    if (child_item.HasDropDownItems)
                    {
                        child_item.DropDownItemClicked += new ToolStripItemClickedEventHandler(child_item_DropDownItemClicked);
                        CreateEvents(menu, child_item);
                    }
                }
                menu.ItemClicked += new ToolStripItemClickedEventHandler(child_item_DropDownItemClicked);
            }
            else
            {
                foreach (ToolStripMenuItem child_item in item.DropDownItems)
                {
                    if (child_item.HasDropDownItems)
                    {
                        child_item.DropDownItemClicked += new ToolStripItemClickedEventHandler(child_item_DropDownItemClicked);
                        CreateEvents(menu, child_item);
                    }
                }
            }
           
        }

        void child_item_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            MessageBox.Show(e.ClickedItem.Text);
        }

Example:

LoadDynamicMenu( XmlPath );
CreateEvents(menustrip1, null);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
countrymeisterAuthor Commented:
That was awesome, thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.