TreeView Contro; in C#: How to highlight a selected node by Mouse-Right-Click ? RRS feed

  • Question

  • In a TreeView control, a normal mouse-left-click highlights the selected node. However, a mouse-right-click does NOT. How can a mouse-right-click highlight the specified node in C# ?


    • Déplacé CoolDadTx lundi 17 janvier 2011 14:24 Not IDE related (From:Visual C# IDE)
    samedi 15 janvier 2011 03:30



    Hi  TFukuda-DocumentFusion,


    We just need to execute the following code when we use the mouse right button click on the node:

    // Sets the tree node that is currently selected in the tree view control.
    treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y);  

    And the complete method is:

    private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
     if (e.Button == System.Windows.Forms.MouseButtons.Right)
     treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y); 

    If there's any concern, please feel free to follow up.


    Have a nice day!

    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    lundi 17 janvier 2011 08:58

Toutes les réponses