Перейти к основному контенту
Центр разработки для Windows

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

  • Вопрос

  • 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# ?


    • Перемещено CoolDadTx 17 января 2011 г. 14:24 Not IDE related (From:Visual C# IDE)
    15 января 2011 г. 3: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.

    17 января 2011 г. 8:58

Все ответы