473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Treeview Node Loses highlight when context menu opens

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.
Nov 16 '05 #1
4 11562
Try setting the treeview's "Hide Selection" property to false.
"Phill" <wa********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
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.

Nov 16 '05 #2
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?
Nov 16 '05 #3
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.

--
-Philip Rieck
http://philiprieck.com/blog/

-
"Phill" <wa********@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
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?

Nov 16 '05 #4
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

"Phill" wrote:
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.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric | last post by:
I implemented owner drawing on the main and context menus of my main form. It works fine. There is also a notify icon control that has a context menu. When the icon is in the status bar, it...
5
by: Dean L. Howen | last post by:
Dear friends, Could we determine when context menu should appear?
2
by: Juan Romero | last post by:
Hey guys, I am trying to detect a node right click event, but I can't seem to find a way do this. The only way I found to get to a point where I know the user clicked the node is by checking...
2
by: Claire | last post by:
I've a treeview control containing a root node with several children on a windows form. I select a node with a left mouse button click. I then select one of the other nodes with right mouse click...
2
by: anujzcool | last post by:
Hi All, I want to capture window messages when context menu is opened and user is scrolling in it or just moving his mouse outside it. I tried with all the possible window messages and nothing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.