I have a treeview opening a contextMenuStrip on right click. However the right click would not select the node that it right clicks on. How should I make it so the right click will select the node, and open the contextMenuStrip on that node?
I tried this:
-
-
private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
-
{
-
if (e.Button == MouseButtons.Right)
-
{
-
treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);
-
}
-
}
-
I found solutions online all points to using MouseDown or MouseUp as a solution. It selects the node when my right mouse button is still holding down. However on release of the button, the node that I selected before the right click becomes the selected node and contextMenuStrip opens on this selected node.
I tried setting a breakpoint in the if statement of MouseDown, however, it seems like it never even called the function! How weird...