Right Clicking a node in a tree view

Z

Zach

Sometimes I right click a node in a tree view and display a context
menu. When the user chooses an option from the context menu, I want
different things to happen depending on which node was selected. This
seems pretty common and straightforward, the problem arises when I have
node A selected, then I right click Node B. The information does not
seem to be maintained anywhere about the fact that it was actually Node
B that was clicked. If I use treeView.SelectedNode, then result is
Node A. Is my only option to maintain an additional field called
TempSelectedNode or something that is updated every time a node is
either right clicked or left clicked? Or is there a standard way to
handle this?

Thanks
 
F

FUnky

This is a repeated question.
You have to select the node via code in the treeview_mouseup event.

FUnky
 
S

Stoitcho Goutsev \(100\)

Zach,

Right click doesn't change the current node selection. What I usually do is
to hook on three view MouseUp event (since the context menu shows up on
mouse up)
and in the event handler I do something like

TreeNode clickedNode = this.columnsPicker.GetNodeAt(e.X, e.Y);

if(clickedNode != null)
{
this.treeView1.SelectedNode = clickedNode;
}
 

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