Select Node in TreeView with VBA

I have TreeViewinside UserFormin Excel. When a Node is selected from TreeView, a is ListBoxpopulated with data.
When an item is ListBoxdouble-clicked, a separate one is displayed UserForm, which allows the user to do things.
When the user returns to TreeView UserForm, I want to Nodebe selected earlier to be highlighted.

The problem is that it UserFormbasically dumps itself, and I cannot figure out how to choose Nodeusing VBA.

I am at the point where I am discussing whether I can simply manually trigger the event NodeClick, since everything I tried failed.

Any tips?

+5
source share
4 answers

I know this is an old question, but I had problems finding a decent answer, so we go. An index or key is not always available. When creating, I put the full path of the node in node.tag. When double-clicking, I return the tag value, and then I look at the treeview node collection for the tag. Too much? ineffective? maybe, but his work likes charm every time, and I can use my own identifiers in the tag based on the purpose of the tree structure. Search Code:

Sub MyTreeview_FindNode(strKey As String)
Dim myNode As Node

   For Each myNode In Me.Treeview.Nodes
       If myNode.Tag = strKey Then
          myNode.Selected = True
          myNode.EnsureVisible
          End If
       Next
End Sub 
+3
source

You have several options. First, when the TreeView UserForm displays a second UserForm, you either need to:

  • node ( ). , node . IIRC, "" node, TreeView.Select node, TreeView.FindNode. - -
  • TreeView UserForm (Me.Hide). UserForm ( / ), TreeView UserForm (TreeViewForm.Show).
+1

: objTreeview.Object.Nodes(KEY_NAME).selected = TRUE

KEY_NAME - (), node

0

Excel :

TreeView1.Nodes(key).Selected = True
-1

All Articles