Simulate Menu Click

In VB.net, I cannot figure out how to programmatically call a sub-menu, except in the same procedure that I first create the menu.

Private Sub InitializeMenu
...
        Dim menuView As New ToolStripMenuItem
        menuView.Text = "View" 'Assign a text value to the MenuStripItem
        mnuMain.Items.Clear()
        mnuMain.Items.Add(menuView) 'add the MenuStripItem to the main menu

...
           'add a submenu for this grid
            Dim subMenu As New ToolStripMenuItem
            subMenu.Text = GRID_NAME(iGrid)
            menuView.DropDownItems.Add(subMenu)

...
                 menuView.DropDownItems(iGrid).PerformClick()

but I cannot make the performClick work if I am outside of this procedure.

it doesn't seem to make sense to dimension a new one in a new procedure.

This is probably obvious but I'm known for overlooking the obvious.  Thanks for your help!
LovinSpoonfulAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
You would need to declare the submenu in a location which is accessible in both above code and the code where you want to performclick. Probably at class level.
0
 
LovinSpoonfulAuthor Commented:
Also, there is another submenu below each menu above.
How do I get retrieve the name of each, and then performClick on the one I want?
0
 
LovinSpoonfulAuthor Commented:
Thanks.  This works.  I also made a generic list of submenu items at the class level so that I could access the 3rd level of menu indentation (subsubMenu) from anywhere within the class.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.