我有一个带有节点的TreeView。
使用以下选项禁用选择:
Private Sub TreeList_BeforeSelect(sender As Object, e As TreeViewCancelEventArgs) Handles TreeList.BeforeSelect
e.Cancel = True
End Sub
我无法找到方法,找出哪个节点(因为会有多个节点)打开ContextMenuStrip(所以我可以用它删除它)。
根据评论,现在可行:
Dim WhichItemIsIt As TreeNode
Private Sub TreeList_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeList.NodeMouseClick
WhichItemIsIt = e.Node
End Sub
Private Sub RemoveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RemoveToolStripMenuItem.Click
TreeList.Nodes.Remove(WhichItemIsIt)
End Sub
答案 0 :(得分:1)
我认为这样可以解决问题:
Private lastClickedNode As TreeNode
Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
lastClickedNode = e.Node
End Sub
右键单击节点会在显示菜单之前将其分配给该字段,然后您可以从菜单项的Click
事件处理程序或其他任何内容访问该节点。