Override events in TreeView
-
Helo One problem whit the TreeView in VB.NET, is that right-clicking don´t select the node. Im trying to add Context-menu´s to my Node´s. But I cant figure out a way to catch the node that was right-clicked. :confused:
:cool::-DHelo If any one is intressted - I solved the problem..... What I did: A event handler tied to the MouseUp Private Sub OnTreeViewMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles TreeViewA.MouseUp Dim pt As Point pt = New Point(e.X, e.Y) recursNodeSearch(pt, TreeViewA.Nodes) End Sub And the Sub that do the trapping: Private Sub recursNodeSearch(ByVal pt As Point, ByVal nodes As TreeNodeCollection) Dim nNode As TreeNode For Each nNode In nodes Try If nNode.Bounds.Top <= pt.Y And nNode.Bounds.Bottom >= pt.Y Then 'This check the row, is you want to check the exact location. ' If nNode.Bounds.Contains(pt) Then '=================================== TreeViewA.SelectedNode = nNode Exit Sub ElseIf nNode.IsExpanded Then recursNodeSearch(pt, nNode.Nodes) End If Catch End Try Next End Sub