C# WinForms: I need the right mouse click to select a TreeView node
Posted on 2012-09-13
I have a working TreeView and context menu which comes up when the right mouse button is clicked on various nodes and node types. Fine.
But, if I click on a node which is not selected, the context menu pops open but the selection jumps back to the previously selected node. This is errant behavior I need to fix.
I want the right click to select that node.
I would think this would work:
internal void TvMainMouseUp(MouseEventArgs e)
if (e.Button == System.Windows.Forms.MouseButtons.Right)
_view.TreeViewRules.SelectedNode = _view.TreeViewRules.GetNodeAt(_view.TreeViewRules.PointToClient(Cursor.Position));
but it doesn't