TreeView using

A

Aleksey

Hi, All!

I have a problem with TreeView component. My TreeView consists of two
nodes Node1 and Node2. On click of right mouse button TreeView has event. In
this event I check wich node is selected. At the start Node1 is selected.
But when I do right click on Node2 the selected node remain Node1. It
changed only after left click.
Q: How can I check on wich node was right click? Or how can I make
TreeView to change selected node by node that gets right click?

Thanks a lot
 
F

Frans Bouma [C# MVP]

Aleksey said:
Hi, All!

I have a problem with TreeView component. My TreeView consists of
two nodes Node1 and Node2. On click of right mouse button TreeView
has event. In this event I check wich node is selected. At the start
Node1 is selected. But when I do right click on Node2 the selected
node remain Node1. It changed only after left click.
Q: How can I check on wich node was right click? Or how can I make
TreeView to change selected node by node that gets right click?
This is a problem with the treeview control. To solve it do:
In the MouseDown event, check if the mousebutton is the
rightmousebutton like:
if(e.Button==MouseButtons.Right)
{
// here select the node, like:
_myTreeView.SelectedNode = _myTreeView.GetNodeAt(e.X,e.Y);

// set the context menu for the treeview here. That is, if
// SelectedNode is of course not null
}

FB

--
 

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