Re: Treeview Context Menu
- From: "Tom Dacon" <tdacon@xxxxxxxxxxxxxxxx>
- Date: Tue, 10 Jun 2008 08:44:40 -0700
Scott, MouseDown is your friend.
In the mouse down event handler, e.Button tells you whether it's a
right-button or left-button, and the TreeView's GetNodeAt(e.x, e,y) gives
you the tree node. From the tree node, you can traverse up the node path to
find out where it is in the tree, to decide on whether or not to supply
context menu services.
Now, still in the mouse down event handler, store in a private instance
variable a reference to the node, so that the context menu items' click
handlers don't have to depend on whether or not it's currently selected, and
display the context menu at the mouse coordinates.
In the context menu item's click handler, you pick up the node from the
variable you stored above, and do whatever needs doing.
By the way, my users find it confusing for one tree node to be selected and
highlighted, while a context menu is running on a different node. So in my
mouse down handler, after I've found the node the mouse is over, I routinely
make it the treeview's selected node.
Tom Dacon
Dacon Software Consulting
"Scott Lyon" <ScottLyon@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:41933017-6B46-4D66-8AFB-5DEB8671D67A@xxxxxxxxxxxxxxxx
This should be a simple question: I am working on an application that
loads
data into a Treeview. The structure of the data is such that the top level
of
the tree is two nodes: Projects and Favorites. Under those nodes is
potentially an infinite number of node going down many levels deep
(populated
as the user does the expand on each, rather than loading the whole table
at
once that would probably take weeks).
I need to add a context menu to the form such that it's enabled when the
user picks on any child (no matter how deep) of the Favorites branch, but
no
menu when the user picks a child of the Projects branch.
Here's the problem - in the Click event of the treeview (where I would
think
I'd check what is clicked and enable/disable the context menu
accordingly), I
have no way to tell the item that's been right-clicked. Sure, if they
left-click on it first, I can tell that.
But I cannot assume that they will left-click on the item first. In fact,
in
most cases, they will have already left-clicked on a DIFFERENT item before
right-clicking on the item they meant to.
Any ideas?
.
- Prev by Date: Re: How can I change the Start Page News channel
- Next by Date: RE: Treeview Context Menu
- Previous by thread: Re: How can I change the Start Page News channel
- Next by thread: RE: Treeview Context Menu
- Index(es):