You are here : Blog
Search_Blog Minimize

KHSW Soft Blog Minimize

If you use the default TreeView in Visual Studio 2003, the SelectedNode property doesn't always return the correct selected node in the Click event.

If you inherit from the TreeView, you can override the OnMouseDown event with this code:

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
Me.SelectedNode = Me.GetNodeAt(New Point(e.X, e.Y))
MyBase.OnMouseDown(e)
End Sub


Otherwise, you can add this code to your form in the OnClick event of the Treeview:
Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
TreeView1.SelectedNode = TreeView1.GetNodeAt(New Point(e.X, e.Y))
End Sub


Copyright 2007 by KHSW Soft BVBA
Privacy StatementTerms Of Use