none
TreeView - Set focus RRS feed

  • Question

  • Hi,

    How do I set focus on a node in a treeview?

    TreeView1.SetFocus()

     I would imagine, that in parenthesis I should use a Index of some kind. I tried with a Node.key but that only work with a click node evnet.

    Thursday, July 26, 2018 8:22 PM

Answers

  • Hello Nikki Dee,

    Sorry for error, I used to test in Form_Initialize event, so I missed one operation.

    Please try

    Me.TreeView1.Nodes("R12").Selected = True
    Me.TreeView1.SetFocus

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Nikki Dee Friday, July 27, 2018 10:33 AM
    Friday, July 27, 2018 10:17 AM

All replies

  • Hello Nikki Dee,

    If you know the key of the node, please try code like below ("R12" is the key of the node)

    Me.TreeView1.Nodes("R12").Selected = True

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 27, 2018 1:50 AM
  • Hi Terry,

    Thank you for your answer again :)

    It works, but it's not highlighted as I wanted to, it only expand that "Group" it is in.

    Kind regards

    Nikki

    Friday, July 27, 2018 8:31 AM
  • Hello Nikki Dee,

    Sorry for error, I used to test in Form_Initialize event, so I missed one operation.

    Please try

    Me.TreeView1.Nodes("R12").Selected = True
    Me.TreeView1.SetFocus

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Nikki Dee Friday, July 27, 2018 10:33 AM
    Friday, July 27, 2018 10:17 AM