1
votes

I'm using the MS Treeview Control v6 on my form, and the default behavior of the Treeview control seems to be that child nodes that belong to a different branch than the one you click in automatically collapse. So if there's a Treeview that looks like this:

  • Root
    • Child 1
    • Child 2
    • Child 3
  • Parent
    • Child 4
    • Child 5
    • Child 6

If I click on Child 5, nodes for Child 1 through 3 automatically collapse (which is not desired) as shown:

  • Root
  • Parent
    • Child 4
    • Child 5
    • Child 6

Here is code for the treeview:

Private Sub Form_Load()
   Dim nodX As Node
   Set nodX = TreeView1.Nodes.Add(, , "R", "Root")
   nodX.Expanded = True
   Set nodX = TreeView1.Nodes.Add(, , "P", "Parent")
   nodX.Expanded = True
   Set nodX = TreeView1.Nodes.Add("R", tvwChild, , "Child 1")
   Set nodX = TreeView1.Nodes.Add("R", tvwChild, , "Child 2")
   Set nodX = TreeView1.Nodes.Add("R", tvwChild, , "Child 3")
   Set nodX = TreeView1.Nodes.Add("P", tvwChild, , "Child 4")
   Set nodX = TreeView1.Nodes.Add("P", tvwChild, , "Child 5")
   Set nodX = TreeView1.Nodes.Add("P", tvwChild, , "Child 6")
End Sub

One approach to resolving this that I could determine would be to expand each node in the Treeview when a node click event happens:

For Each nodX In Me.Treeview1.Nodes
   nodX.Expanded = True
Next nodX

However the problem with this is that I have hundreds of nodes in the Access file I am working on, and that code undoes any manual collapsing / navigation of Treeview nodes I may have done.

I've looked into the documentation but there doesn't seem to be any setting to prevent this default behavior of nodes automatically collapsing from happening. I'm hoping that maybe someone does know of a property that can be adjusted to address this issue.

*Edit: More specifically, when looking at a Treeview I have with more nodes, the behavior is that when I click on a node in a different branch, it is the branch that was previously selected that collapses (not necessarily all other branches).

Here's the Treeview properties for reference: Treeview Control Properties

1
I use the Treeview Control v6 in a couple of forms, and have never seen this behavior. Are you sure that there is no code that specifically does this in your form? -- Can you add a screenshot of the object properties of the TreeCtrl?Andre
I've added a screenshot of the properties to the post.Gabe R

1 Answers

1
votes

Found it. It's the SingleSel property.

If you uncheck this, the strange behavior should be gone (it appears for me if I check this property).

The documentation (I have an old CMCTL198.CHM for the Common Controls) isn't very helpful on this --

False (Default)   The item doesn't expand when selected. 
True              The item expands when selected.