Treeview Node Loses highlight when context menu opens

P

Phill

Here's what I'm doing to make the right context mnue show up based on
what node was cliked:

private void tvwMenu_MouseUp(object sender, MouseEventArgs e)
{
//Select Node When Right Clicked & Set Context Menu To Use
if( e.Button == MouseButtons.Right )
{
TreeNode node = tvwMenu.GetNodeAt( new Point( e.X, e.Y ) );
if( node != null )
{
TreeNodeMenuTag tag = (TreeNodeMenuTag)node.Tag;
tvwMenu.SelectedNode = node;
tvwMenu.ContextMenuStrip = (tag.isMenu) ? cmnuMenuNode :
cmnuProgramNode;
}
}
}

It works, but unlike the Solution Explorer treeview in VS when you
right click on a node the node loses its highlight. I don't like this
cux it makes it less obvious which node you are operating on. Anyone
know how to fix this?

Thanks.
 
P

Phill

Thanks for the tip it does improve things having the highlight still
show when the context menu takes focus.

Still, you have to click like 2x in order to right click another node.
Once to cause the context menu to loose focus and again to get the
context menu to appear on the new node.

In VS's Exlorer or even Windows Explorer though you don't have to.
Just right clicking another node (eben if the context menu is already
up) works.

Any idea how to accomplish this?
 
P

Philip Rieck

In your mousedown or up event handler (where you're determining what node
was clicked on), you'll have to programmatically set the selection to that
node. If you're relying on the treeview's selected node property, you'll
have to abandon that and call the methods to get the node based on the mouse
position.
 
G

Guest

Hello Phill, I'm Willian from Brazil ...

You most change the mouse position for some context. You can use method
PointToClient of treeview object. This method return a point in client
context.
For example:

Point position = myTreeview.PointToClient(new Position(e.X, e.Y));
TreeNode node = myTreeview.GetNodeAt(position);

Try it!

[ ]'s

Willian
 

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