how to add mouse right-click event to tree w/out overriding defaul

G

Guest

by default when you right click a tree the control selects the node

if you add a right-click event (so that I can put sepearate ContextMenus
depending on what type of node the user clicked on) then that default
behavior is overrided, and it no longer selects the node the user
right-clicked on. Now my event is wrong because I want to use SelectedNode
but the SelectedNode turns out to be whatever was previously selected instead
of what the user just clicked on.

how do I solve this problem?
 
P

Patrick Steele

by default when you right click a tree the control selects the node

if you add a right-click event (so that I can put sepearate ContextMenus
depending on what type of node the user clicked on) then that default
behavior is overrided, and it no longer selects the node the user
right-clicked on. Now my event is wrong because I want to use SelectedNode
but the SelectedNode turns out to be whatever was previously selected instead
of what the user just clicked on.

how do I solve this problem?

Instead of handling the MouseDown event, you could inherit from the
TreeView and override the OnMouseDown method -- and make sure you call
base.OnMouseDown() first to let the base class do it's code first (which
should include selecting the node right-clicked on).
 

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