Treeview NodeClick

R

rob willaar

I seem to miss then treeview NodeClick
How can i check if a node is clicked when it is selected?
 
C

Cor Ligthert

Rob,

Do you mean something as this?

Beneath this is exactly what you ask, this is shows when it is selected, so
clicked)
\\\
Private Sub TreeView1_AfterSelect _
(ByVal sender As Object, ByVal e As _
System.Windows.Forms.TreeViewEventArgs) _
Handles TreeView1.AfterSelect
Dim mynodeText As String = e.Node.Text
End Sub
///
\\\
Private Sub TreeView1_Click(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles TreeView1.Click
Dim myNodeText As String = _
DirectCast(sender, TreeView).SelectedNode.Text
End Sub
///
I hope this helps?

Cor
 
R

rob willaar

Hi Cor,

i have tried that before but:
This will also trigger if i click someware else on the treeview.
 
H

Herfried K. Wagner [MVP]

* "rob willaar said:
I seem to miss then treeview NodeClick
How can i check if a node is clicked when it is selected?

Add a handler to the treeview's 'MouseUp' event and use the treeview's
'GetNodeAt' method to get the node under the cursor.
 
D

Dany P. Wu

rob willaar said:
Hi Cor,
i have tried that before but:
This will also trigger if i click someware else on the treeview.

Hi Cor,

The Click event is raised when you click on any item in the treeview,
including the parent node you're trying to expand. In the end I ended up
using the DoubleClick event - and the users seem to be reasonably happy with
that.

HTH
Dany.
 
C

Cor Ligthert

Rob,

The second sample does, however the first in my opinion not?

Where is my mistake?

However that first fires after the click when that is on a select of a node.

When you want first to select and than do an extra click, than I think that
you have to go to the solution from Dany. (Because there should be a distict
between a click and a double click).

Cor
 
R

rob willaar

Hi All,

Herfried got the solution to create the NodeClick event.
The code is like follows to call OpenMenu:
Private Sub tvMain_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles tvMain.MouseUp

Dim pt As Drawing.Point

pt.X = e.X

pt.Y = e.Y

Dim tn As TreeNode = tvMain.GetNodeAt(pt)

OpenMenu(GetTVMenukey(tn))

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top