By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

detect mouse event on node of a treeview

P: n/a
Sam
Hi,
I'd like to get the selected node when the user select a node in my
treeview. I know how to get the selected node, what I don't know is how
to detect that the user has selected a new node.

What methods should I use ?
thx

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I basically used a static variable to keep the old value of the
selected node and check to see if the new selected node was the same as
the old node. If not then I know they selected a new node.

Nov 21 '05 #2

P: n/a
"Sam" <sa**************@voila.fr> schrieb:
I'd like to get the selected node when the user select a node in my
treeview. I know how to get the selected node, what I don't know is how
to detect that the user has selected a new node.


\\\
Private Sub TreeView1_AfterSelect( _
ByVal sender As Object, _
ByVal e As TreeViewEventArgs :
) Handles TreeView1.AfterSelect
Static LastNode As TreeNode
Dim CurrentNode As TreeNode = _
Me.TreeView1.GetNodeAt(Me.TreeView1.PointToClient( Cursor.Position))
If Not CurrentNode Is LastNode Then
LastNode = CurrentNode
If Not CurrentNode Is Nothing Then
MsgBox(CurrentNode.Text)
Else
MsgBox("No node selected!")
End If
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3

P: n/a
Sam
thanks to both of you
finally here is what i've done

Private Sub tvRelations_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
tvRelations.AfterSelect

If tvRelations.SelectedNode.Nodes.Count = 0 Then
txtTable1.Text = tvRelations.SelectedNode.Parent.ToString
txtTable2.Text = tvRelations.SelectedNode.ToString
End If
End Sub

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.