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

  • Domanda

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

    Thanks

    • Spostato CoolDadTx lunedì 17 gennaio 2011 14:24 Not IDE related (From:Visual C# IDE)
    sabato 15 gennaio 2011 03:30

Risposte

  •  

    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.

    lunedì 17 gennaio 2011 08:58
    Moderatore

Tutte le risposte