Treeview SelectedNode object

  • Thread starter Thread starter hark
  • Start date Start date
H

hark

Hi,

Does anyone know how to access this property to get to current Node detail?
It keep giving me the previous node clicked..Is there another property or
object that would give you the current Node? ..This code works ok if i click
on the selected item twice..

Thanks,

Hark.
Private Sub trvText1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles trvText1.Click

Try

stbTantest.Panels(0).Text = CType(sender,
TreeView).SelectedNode.FullPath

Catch ex As Exception

stbTantest.Panels(0).Text = ex.Message

End Try

End Sub
 
Thanks very much, it works fines with AfterSelect event..but Click event
still references the previous selected node..any idea why or how to remedy
this?

Thanks in advance.
 
* "hark said:
Thanks very much, it works fines with AfterSelect event..but Click event
still references the previous selected node..any idea why or how to remedy
this?

Quick and Dirty:

\\\
Private Sub TreeView1_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles TreeView1.MouseUp
Dim t As TreeNode = Me.TreeView1.GetNodeAt(e.X, e.Y)
If t Is Nothing Then
MsgBox("No node selected")
Else
MsgBox(t.Parent.Text)
End If
End Sub
///
 
Thank you very much, at least i have another way of getting to the selected
node. Seems my problem is caused by me trying to use Click Event. It seems
to fire even before MouseUp event..i had to use MouseDown to set
SelectedNode so that Click will recognise the new Node.

Thanks again,

Hark.
 
Addendum:
Quick and Dirty:

\\\
Private Sub TreeView1_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles TreeView1.MouseUp
Dim t As TreeNode = Me.TreeView1.GetNodeAt(e.X, e.Y)
If t Is Nothing Then
MsgBox("No node selected")
Else
MsgBox(t.Parent.Text)
End If
End Sub
///

I forgot to mention that this will fail if the node is selected through
the keyboard.
 
Back
Top