VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Display context (popup) menu on TreeView control nodes

by Sam Fernandez (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 27th September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Display context (popup) menu on TreeView control nodes

Rate Display context (popup) menu on TreeView control nodes




Private Sub Form_Load()
   'Create and display a treeview control

   Dim nodX As Node  ' Declare Node variable.
   
   ' Set Treeview control properties.
   TreeView1.LineStyle = tvwRootLines  ' Linestyle 1
   
   ' First node with 'Messages' as text.
   Set nodX = TreeView1.Nodes.Add(, , "Main", "Mail")
   Set nodX = TreeView1.Nodes.Add("Main", tvwChild, "Inbox", "Inbox")
   Set nodX = TreeView1.Nodes.Add("Main", tvwChild, "Outbox", "Outbox")
   Set nodX = TreeView1.Nodes.Add("Main", tvwChild, "Drafts", "Drafts")
   
   Set nodX = TreeView1.Nodes.Add(, , "Contacts", "Contacts")
   Set nodX = TreeView1.Nodes.Add("Contacts", tvwChild, "Customers", "Customers")
   Set nodX = TreeView1.Nodes.Add("Contacts", tvwChild, "Suppliers", "Suppliers")
   Set nodX = TreeView1.Nodes.Add("Contacts", tvwChild, "Sales", "Sales")

End Sub



Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)

   
   Dim myNode As Node
   On Error GoTo Mali
   If Button = vbRightButton Then
      Set myNode = TreeView1.SelectedItem
      Select Case myNode.Parent.Key
      Case "Main"
         Me.PopupMenu mnu1   'assuming mnu1,2 menu item exists
      Case "Contacts"
         Me.PopupMenu mnu2
      End Select
   End If
   
   Exit Sub
Mali:
   'ignore if parent node is selecte
   If Err = 91 Then
      Exit Sub
   End If
   
   
End Sub


Download this snippet    Add to My Saved Code

Display context (popup) menu on TreeView control nodes Comments

No comments have been posted about Display context (popup) menu on TreeView control nodes. Why not be the first to post a comment about Display context (popup) menu on TreeView control nodes.

Post your comment

Subject:
Message:
0/1000 characters