[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3309
  • Last Modified:

find the treeview node level with a click on the node in vb. net

I want to return a treeview node level with a single mouse click (1, 2 or 3).  I'm loading a treeview from a database (which works just peachy) and need to know what level I've clicked.  There are up to three levels: parent, child, grandchild.  What I want to do is right click on a node to get a specific context menu to deal with that node at that level.  Each level will have it's own context menu.

This works to a point.  But I get the level down one from the node I click.  In orther words, if I click the parent node, I get the child node text.
    Private Sub TreeView1_MouseDown(ByVal sender As Object, _
                    ByVal e As System.Windows.Forms.MouseEventArgs) _
                    Handles TreeView1.MouseDown
        If e.Button = MouseButtons.Right Then
            Dim n As TreeNode = TreeView1.GetNodeAt(e.X, e.Y)
            mnuContextLevel1.Show(TreeView1, New Point(e.X, e.Y))
            MsgBox(TreeView1.SelectedNode.Nodes(TreeView1.SelectedNode.Level).ToString)
        End If
    End Sub

I'm kinda hoping it's a simple solution since I'm running out of points.  If I'm not clear enough, please let me know.

Randy
0
StateGuy
Asked:
StateGuy
  • 2
  • 2
1 Solution
 
Malik1947Commented:
Why not simply use the level?





MsgBox(TreeView1.SelectedNode.Level).ToString)

Open in new window

0
 
StateGuyAuthor Commented:
I got an error message:
"Overload resolution failed because no accessible 'ToString' can be called with these arguments."

0
 
Malik1947Commented:
My bad.


  	
 
MsgBox(TreeView1.SelectedNode.Level.ToString)

Open in new window

0
 
StateGuyAuthor Commented:
OO-RAH!  And don't worry about the misplaced paren.  I made a mistake once myself...
<humor inetnded>
Thanks again.

Randy
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now