Right Clicking a node in a tree view

  • Thread starter Thread starter Zach
  • Start date Start date
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
 
This is a repeated question.
You have to select the node via code in the treeview_mouseup event.

FUnky
 
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;
}
 
Back
Top