Treeview Question

  • Thread starter Thread starter Randall Hale
  • Start date Start date
R

Randall Hale

I'm trying to dynamically create values for a context menu (popup),
depending upon which node is highlighted in a Treeview control. This is not
a problem, if you select the node with the left mouse button and THEN
right-click (the context menu then displays an item IAW a Tag value
previously assigned to each node). If you only use the right mouse button,
however, it appears that the given node is selected but this is not the
case; it is only highlighted, and all you get is the old value for the
previously selected node, which had to have been selected via the left mouse
button first.

A one-click process seems more natural and intuitive to me; and it should be
possible to select a given node with either mouse button. Any suggestions
as to how to achieve this. Lots of hair pulling so far but no luck.

Regards,

Randall Hale
 
* "Randall Hale said:
I'm trying to dynamically create values for a context menu (popup),
depending upon which node is highlighted in a Treeview control. This is not
a problem, if you select the node with the left mouse button and THEN
right-click (the context menu then displays an item IAW a Tag value
previously assigned to each node). If you only use the right mouse button,
however, it appears that the given node is selected but this is not the
case; it is only highlighted, and all you get is the old value for the
previously selected node, which had to have been selected via the left mouse
button first.

That's a FAQ:

<http://www.google.com/groups?ie=UTF-8&q=Contextmenu+treeview+group:*dotnet*>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
Thanks, Herrfried. That did the trick (I've been out of the loop and hadn't
seen this question before).

For quick reference for others, this is what finally worked for my
situation:

Sub ContextMenu1_PopUp ( ByVal o As Object, ByVal e As System.EventArgs )
Handles ContextMenu1.Popup
Dim clickedNode As TreeNode = Treeview1.GetNodeAt (
Treeview1.PointToClient ( Cursor.Position ) )
With ContextMenu1.MenuItems
.Clear ( )
.Add ( clickedNode.Tag)
End With
End Sub

Pretty simple but sequence IS scored. I tried something similar during the
MouseUp event for the Treeview control; passing a Point derived from the
MouseEventArgs to the Treeview's GetNodeAt method, as the documentation
suggests. That doesn't help here, however, because the menu pops up before
the MouseUp is called. I knew I was missing something obvious. ;-)

Thanks All!

Randall hale
 
Back
Top