我想在点treeview控件时加上右键弹出菜单,根结点和子结点显示的菜单内容不一样,不知道能不能实现的啊 (最好贴出代码)

解决方案 »

  1.   

    Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
      Dim tmpNode       As Node
      
      If Not Button = vbRightButton Then Exit Sub
      Set tmpNode = TreeView1.HitTest(x, y)
      If tmpNode Is Nothing Then Exit Sub
      MsgBox tmpNode.Key  '选中节点的关键字
      MsgBox tmpNode.Text  '选中节点的显示字符
      
      '添加自己的菜单处理代码
      
      Set tmpNode = Nothing
    End Sub
      

  2.   

    Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
      Dim tmpNode       As Node
      
      If Not Button = vbRightButton Then Exit Sub
      Set tmpNode = TreeView1.HitTest(x, y)
      If tmpNode Is Nothing Then Exit Sub
       
      If tmpNode.Index = 1 Then
      '选中的是根节点,使用"rootline"样式
      
      End If
      If tmpNode.Children > 0 Then
      '选中的是根节点或是枝节点
      
      Else
      '选中的是叶节点
      
      End If
      
      Set tmpNode = Nothing
    End Sub
      

  3.   

    '我的问题就是做一个以下的列子
    '就向这样
    '
    'vb___
    '     |___基础___
    '     |          |___最终节点
    '     |          |___最终节点
    '     |___控件___
    '                |___最终节点
    '                |___最终节点
    '
    '我已经把基础和控件那个做出来了,
    '
    '现在问高手。我怎么样才能动态的向"基础" 和 "控件"这个子节点插入那个" 最终节点 "啊?Option ExplicitDim Cur_Node As NodePrivate Sub Form_Load()
            With Me
                 .Text1.Text = ""
                 .Text2.Text = ""
                 .Text3.Text = ""
                 With .TreeView1
                      With .Nodes
                           .Add , , "A_VB", "VB"
                           .Add "A_VB", 4, "B_Base", "基础"
                           .Add "A_VB", 4, "B_Control", "控件"
                      End With
                 End With
            End With
            
            Me.TreeView1.Nodes(1).Expanded = True
            
    End Sub
    Private Sub menu_AddNode_Click()
            On Error GoTo err1
            
            Dim strTemp As String
            
            If Not Cur_Node Is Nothing Then
                  strTemp = InputBox("请您输入子节点的名称:", "系统提示", "temp")
                  Me.TreeView1.Nodes.Add Cur_Node.Key, 4, "C_" & Cur_Node.Key & "_" & strTemp, strTemp
                  Cur_Node.Expanded = True
                  MsgBox "添加完毕!", vbInformation, "系统提示"
            End If
            Exit Sub
    err1:
            If Err.Number <> 0 Then
                   MsgBox "您输入的名字,已经存在,请换个名字!", vbInformation, "系统提示!"
                   Err.Clear
            End If
    End SubPrivate Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
            
            
            Set Cur_Node = Me.TreeView1.HitTest(x, y)
            
            If Not Cur_Node Is Nothing Then
                  With Me
                       .Text1.Text = Cur_Node.Key
                       .Text2.Text = Cur_Node.Text
                       .Text3.Text = Left$(Cur_Node.Key, 1)
                  End With
                  
                  Me.TreeView1.SelectedItem = Cur_Node
                  
                  If Button = 2 Then
                     Select Case Left$(Cur_Node.Key, 1)
                            Case "A"
                                 Me.menu_1.Visible = True
                                 Me.menu_2.Visible = False
                                 Me.menu_3.Visible = False
                                 Me.menu_AddNode.Visible = False
                                 PopupMenu menu_R
                                 
                            Case "B"
                                 Me.menu_2.Visible = True
                                 Me.menu_AddNode.Visible = True
                                 Me.menu_1.Visible = False
                                 Me.menu_3.Visible = False
                                 PopupMenu menu_R
                                 
                            Case "C"
                                 Me.menu_3.Visible = True
                                 Me.menu_1.Visible = False
                                 Me.menu_2.Visible = False
                                 Me.menu_AddNode.Visible = False
                                 PopupMenu menu_R
                                 
                     End Select
                  End If
            
            Else
                  With Me
                       .Text1.Text = ""
                       .Text2.Text = ""
                       .Text3.Text = ""
                  End With
            End If
            
            
    End Sub
      

  4.   

    //pzlk (蜗牛狂奔☆☆☆☆☆) Private Sub Treeview1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)Dim NodX   As Node
    If Button = 2 Then
       Set NodX = Treeview1.HitTest(x, y)
       If NodX Is Nothing Then
       Else
          '添加代码弹出适合你需要的菜单,如Popupmenu mnuMenu
          popupmenu mnuMenu
          
       End If
       Set NodX = Nothing
    End IfEnd Sub//flyingZFX(★我飞★我飞★我飞呀飞★) With Treeview1     .Add "B_Base", tvwChild, "B_Base1" "基础分结点1"
         .Add "B_Control", tvwChild, "B_Control1" "控件分结点1"
    End With如果基础分结点1下面还有分结点的话,依此类推,只是它的分结点的第一个参数的名字要改成基础分结点1的关键字(第3个参数)