-1

我有一个在右键单击 datagridview 时出现的菜单项。用户将鼠标悬停在菜单项上,然后出现其他菜单项的列表,再次重复。给这样的东西。

---------
|  FOO  |---------
---------|  BAR  |------------
          ---------|  FOOBAR  |
                   ------------

仅在第 3 层处理一个事件 (addressof)。话虽如此,我需要从 FOOBAR 中获取 parent.name 和所述父母(祖父母)的 parent.name。

这是我所在的位置:

If currentMouseRow >= 0 AndAlso currentMouseColumn <= 1 Then
            dataGridView_monitorMapping.Rows(currentMouseRow).Selected = True
            mainMenu.MenuItems.Add(New MenuItem("Set Monitor(s) Settings"))
            mainMenu.MenuItems.Add(New MenuItem("Sync Monitor Mapping View", AddressOf triggerSync))
            'list avaliable priorites
            For Each priorityRow As DataRow In priorityTypesDS.Tables(0).Rows
                Dim rowPriortiyName As String = CStr(priorityRow("Priority"))
                Dim subMenu_priorities_item As New MenuItem(rowPriortiyName)
                mainMenu.MenuItems(0).MenuItems.Add(subMenu_priorities_item)
                'list avaliable boards
                For Each boardRow As DataRow In serviceBoardDS.Tables(0).Rows
                    Dim rowBoardName As String = CStr(boardRow("SvcBrd"))
                    Dim subMenu_boards_item As New MenuItem(rowBoardName)
                    subMenu_priorities_item.MenuItems.Add(subMenu_boards_item)
                    'list avaliable types based on board
                    If rowBoardName IsNot Nothing Then
                        Dim availableSvcTypes As DataSet = GetServiceTypes(_objhost, serviceTypes, rowBoardName)
                        For Each svcTypeRow As DataRow In availableSvcTypes.Tables(0).Rows
                            Dim rowSvcTypeName As String = CStr(svcTypeRow(1))
                            Dim subMenu_svcType_item As New MenuItem(rowSvcTypeName, AddressOf triggerSync)
                            subMenu_boards_item.MenuItems.Add(subMenu_svcType_item)
                        Next
                    End If
                Next
            Next
            mainMenu.Show(dataGridView_monitorMapping, New Point(e.X, e.Y))
        End If

和事件处理程序

Public Sub updateMultiRowSettingChange(ByVal Sender As System.Object, ByVal e As System.EventArgs)
    'TODO | Handle selection from right click menu.
End Sub
4

1 回答 1

1

像这样的东西应该让你得到你正在寻找的东西:

Public Sub updateMultiRowSettingChange(ByVal Sender As System.Object, ByVal e As System.EventArgs)
    Dim item As MenuItem = CType(sender, MenuItem)
    Dim parent As MenuItem = CType(item.Parent, MenuItem)
    Dim grandparent As Menu = parent.Parent
End Sub

但是,将菜单项上的标签设置为您需要知道它来自何处的任何信息可能更简单,然后您可以item.Tag在将其转换为 MenuItem 类后进行检查。

于 2012-05-21T14:19:08.337 回答