如果用户单击treeview (向右或向左),而光标不在节点上,我希望将所选节点设置为nothing。我以为单击控件的任何部分都会触发TreeView.MouseClick事件,但它似乎只有在单击节点时才会触发。有没有办法做到这一点?
编辑*我知道如何将所选节点设置为nothing,但当单击控件时无法执行此操作,并且此时没有节点,因为除非单击节点,否则TreeView.MouseClick和TreeView.Click事件似乎不会触发。
Private Sub tvwMain_NodeMouseClick(sender As Object, e As MouseEventArgs) Handles tvwMain.Click
Dim p = New Point(e.X, e.Y)
Dim node As TreeNode = tvwMain.GetNodeAt(p)
If node IsNot Nothing Then
tvwMain.SelectedNode = node
MsgBox("HERE")
Else
tvwMain.SelectedNode = Nothing
MsgBox("TOO")
End If
End Sub
发布于 2016-07-18 08:53:41
TreeNode test = tvwMain.GetNodeAt(tvwMain.PointToClient(Cursor.Position))
If IsNothing(test) Then tvwMain.SelectedNode = Nothing
https://stackoverflow.com/questions/38427231
复制相似问题