Private Sub tvwSecurite_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwSecurite.MouseDown > If e.Button = MouseButtons.Right Then > tvwSecurite.SelectedNode = tvwSecurite.GetNodeAt(e.X, e.Y) > End If >End Sub >>
>>// Set the Tree's ContextMenu >>this.oTree.ContextMenu = this.oContextMenu >> >>// Set the ContextMenu Popup event handler >>this.oContextMenu.Popup += new System.EventHandler(this.oContextMenu_Popup); >> >>private void oContextMenu_Popup(object sender, System.EventArgs e) >>{ >> this.oContextMenu.MenuItems.Clear(); >> MenuItem oItem; >> >> // Create all the appropriate ContextMenu items. This can vary >> // depending on which node in the TreeView was clicked. I have a Node class >> // defined in the control that adds additional functionality to the TreeNode class, >> // so I can tell which type of Node has been selected >> MyTreeNode node = (MyTreeNode)this.oTree.SelectedNode; >> if (node.IsTypeOne) >> { >> // Create one type of context menu >> oItem = new MenuItem("Text For Type One"); >> oItem.Click += new System.EventHandler(this.oMenu_Handler); >> this.oContextMenu.MenuItems.Add(oItem); >> } >> else if (node.IsTypeTwo) >> { >> // Create another type of context menu >> oItem = new MenuItem("Text For Type Two"); >> oItem.Click += new System.EventHandler(this.oMenu_Handler); >> this.oContextMenu.MenuItems.Add(oItem); >> } >>} >> >>private void oMenu_Handler(object sender, System.EventArgs e) >>{ >> MenuItem oItem = (MenuItem)sender; >> >> // Process whichever ContextMenu item was selected >> if (item.Text == "Text For Type One") >> // code to process type one >> else if (item.Text == "Text For Type Two") >> // code to process type two >>} >>>>