Zu Hauptinhalt springen

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

  • Frage

  • 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

    • Verschoben CoolDadTx Montag, 17. Januar 2011 14:24 Not IDE related (From:Visual C# IDE)
    Samstag, 15. Januar 2011 03:30

Antworten

  •  

    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.

    Montag, 17. Januar 2011 08:58
    Moderator

Alle Antworten

  •  

    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.

    Montag, 17. Januar 2011 08:58
    Moderator
  •  

    Hi TFukuda-DocumentFusion,

     

    Have you tried the suggestion? Has this question been solved?

     

    If there's any concern, please feel free to let us know.

     

    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.

    Mittwoch, 19. Januar 2011 20:26
    Moderator
  • Hi Mike,

    Sorry, I was out of town. I am going to try the way you discribed, and will update the status.

    Best regards

    Donnerstag, 20. Januar 2011 17:10
  • Hi Mike,

    Your suggestion works fine. Thank you very much for your support.

    Best regards

    Donnerstag, 20. Januar 2011 23:10
  • Hi TFukuda-DocumentFusion,

     

    You're welcome!

     

    If there's any concern, please feel free to let me know.

     

    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.

    Montag, 24. Januar 2011 05:50
    Moderator