주 콘텐츠로 건너뛰기

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

    Thanks

    • 이동됨 CoolDadTx 2011년 1월 17일 월요일 오후 2:24 Not IDE related (From:Visual C# IDE)
    2011년 1월 15일 토요일 오전 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.

    2011년 1월 17일 월요일 오전 8:58
    중재자

모든 응답

  •  

    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.

    2011년 1월 17일 월요일 오전 8:58
    중재자
  •  

    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.

    2011년 1월 19일 수요일 오후 8:26
    중재자
  • Hi Mike,

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

    Best regards

    2011년 1월 20일 목요일 오후 5:10
  • Hi Mike,

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

    Best regards

    2011년 1월 20일 목요일 오후 11: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.

    2011년 1월 24일 월요일 오전 5:50
    중재자