Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

24. Windows Forms TreeView

24.4 When I right-click a tree node, it does not become selected. How can I make it be selected on a right-click?


Handle the treeview's mousedown event, and if it is the right-click, then explicitly set focus to th enode under the click.

private void treeView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
     if(e.Button == MouseButtons.Right)
     {
          treeView1.SelectedNode = treeView1.GetNodeAt (e.X ,e.Y );
     }
}