ToolStrip Menu click

frobalompires used Ask the Experts™
Hi experts,

Wend I click in submenu dropdown list item on a toolstrip menu I need to retrieve the parent button name and the clik button name as well.

Im able to get the clicked item name but I need as well the parent item name, how cold I get this.

The items that I show on dropdown list are a loop that I made to a folder to get all the files in that folder.

These items in the edit button are the same on the select button, thats the reason why I need the parent button name, so I can take the correct action.

Suppose I mouse over Edit then will show all my files, wend I click in one I need to know if the file is to edit or select.

Check the img.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can loop through the dropdownitems collection of each of your parent menu items and look for a match with the name of the clicked item.

Here's a simple method that you'd call within the click event of your child items
Private Function Blah(ByVal ClickedItemName As String) As String
        For Each ddi As ToolStripDropDownItem In Me.EditToolStripMenuItem1.DropDownItems
            If ddi.Name = ClickedItemName Then
                'do something found the match by name
            End If
End Function

Another method would be to add a value to the tag property of your child items that gave you the information you need.  


Sry, i can't understand...

This function as to be cal wend i click in sub menu item correct???

If yes, thens is impossible because the sub menu is populate by code and i don't know the button name to invocate the function.
End this sub menu cold have 1 item or 1000....

If not then try to explain me

IT Pro/Developer
Top Expert 2008
You can use the OwnerItem() property

    Private Sub myToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myToolStripMenuItem.Click
        Dim menu As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)
    End Sub

Open in new window

Yes, that would be called from the click event of the sub menu item.  In order to do anything, you'll need to respond to an event that occurs when you click the sub menu item.  If you are populating the menu by code, you can add a value to the tag property that tells whether it is select or edit.  
You could use the MouseHover event of the parent menu item to set a value (say "edit" or "select") to a variable.

Private Sub EditToolStripMenuItem1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem1.MouseHover
        sMenu = "Edit"

    End Sub

    Private Sub SelectToolStripMenuItem_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles SelectToolStripMenuItem.MouseHover
        sMenu = "SELECT"
    End Sub

Private Sub CfhToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CfhToolStripMenuItem.Click
    End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial