刀具结构树
    刀具类
        9311系列
           9311-011
          9311-012
          9311-033
       9312系列
           9312-035
       9313系列
    辅具类在(9311系列、9312系列、9313系列)和(9311-011.....)这两级弹出菜单不同的菜单,请问如何操作!
具体的我可能说不清楚,有可以的加我QQ434684189吧!谢谢大家呀!

解决方案 »

  1.   

    node_click事件是左键点击节点即触发事件呀,怎么样右击节点触发呀
      

  2.   

    这个问题由于需要动态菜单,故必须使用API,代码如下:Option Explicit
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Declare Function CreatePopupMenu Lib "user32" () As Long
    Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal sCaption As String) As Long
    Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Long) As Long
    Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Const MF_ENABLED = &H0&
    Private Const MF_SEPARATOR = &H800&
    Private Const MF_STRING = &H0&
    Private Const TPM_RIGHTBUTTON = &H2&
    Private Const TPM_LEFTALIGN = &H0&
    Private Const TPM_NONOTIFY = &H80&
    Private Const TPM_RETURNCMD = &H100&Private Sub Form_Load()
        Me.TreeView1.Nodes.Add(, , "r", "中国").Expanded = True
        Me.TreeView1.Nodes.Add("r", tvwChild, "r1", "四川").Expanded = True
        Me.TreeView1.Nodes.Add("r1", tvwChild, "r11", "汶川").Expanded = True
        Me.TreeView1.Nodes.Add("r1", tvwChild, "r12", "北川").Expanded = True
        Me.TreeView1.Nodes.Add("r", tvwChild, "r2", "甘肃").Expanded = True
    End SubPrivate Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim pos As POINTAPI
        Dim nod As Node, child As Node
        Dim hMenu As Long, i As Long, id As Long
        
        If Button = 2 Then
            Set nod = Me.TreeView1.HitTest(x, y) '获得当前鼠标右键按下时所在的结节
            If nod Is Nothing Then Exit Sub
            If nod.Children = 0 Then Exit Sub
            GetCursorPos pos
            hMenu = CreatePopupMenu()
            Set child = nod.child
            Do While Not child Is Nothing
                AppendMenu hMenu, MF_STRING Or MF_ENABLED, i, child.Text
                Set child = child.Next
                i = i + 1
            Loop
            id = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON Or TPM_LEFTALIGN Or TPM_NONOTIFY Or TPM_RETURNCMD, _
                pos.x, pos.y, 0, Me.hwnd, 0) '选中的菜单条目
            '....在此处加入菜单选择后的代码
            DestroyMenu hMenu
        End If
    End Sub
      

  3.   

    不需要调用API简单的方法点击时 对节点的key进行判断  
    例如 9311系列 为一个系列 若我把它的key设为 Group1
        9312系列 key Group1
        9311-011 key Child1
        9311-012 key Child2
        9311-033 key Child3
    Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Button = 2 then
            If TreeView1.SelectedItem Like "Group*" then   '右键点时自动选中了目标节点
                '弹出对应菜单
            end if
            If TreeView1.SelectedItem Like "Child*" then
                '弹出对应菜单
            end if
        end if
    end sub