Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Child nodes! How to expand treeview

Status
Not open for further replies.

romnew

Programmer
Feb 27, 2002
44
ZA
Hi all
Access97
The code tv.nodes(tv.nodes.count).EnsureVisible expands
the treeview nodes but not the child nodes.
What do I use to make the total tree to expand?
Idont see the "trees" for the wood
Please help
 
Loop through all the child nodes, and set their EnsureVisible property as well, e.g.


Public Sub ExpandAll(ParentNode As Node)
Dim ChildNode As Node
Set ChildNode = ParentNode.Child
Do While Not ChildNode Is Nothing
ChildNode.EnsureVisible
ChildNode.Expanded = True
ExpandAll ChildNode
Set ChildNode = ChildNode.Next
Loop
End Sub
 
Beetee,
Thanks for the response. Will try it out.
Romnew
 
but ... to REALLY expand the 'grandchildern' (nested child nodes, the process needs to be recursive?

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
beeree,
Tried the code but it comes up with error message:
"Object variable or With block not set"
Any suggestions,please
Romnew
 
I really can't tell you anything definitive about your code unless you

1) provide a sample.
2) indicate where the error is occuring.

The sample code works fine in my test case (a directory tree). Can you verify that if the node object you are passing to the function is valid?
 
Beetee,
I may have made a mistake! Will check
What by the way triggers the Expandall sub?
Sorry to be dense.
Romnew
 
No problem, it takes awhile to get used to access alone, much less ActiveX controls. I cheated and cruised the web and downloaded sample code; then was able to locate a .chm file that had documentation.

You can also use your object browser (F2 key) to learn more about various items. Once you have determined properties and methods of the object, you can perform web searches using the ones that interest you, and likely find lots of useful code. You may even find this very message.

You have to trigger the expand-all sub yourself; here's a way to do it:

1) Open the form in design view
2) right click on the tree view control
3) choose 'build event'
4) the module window will open, with the name of the tree control on the left, and a choice of events on the right. Pick a likely event from this list; I think double click would probably be the most reasonable (users will want to double click to expand the entire branch).
5) Once you have chose which event should expand the tree, call the ExpandAll subroutine passing the tree control's selected node as an argument, e.g.

ExpandAll Me.TreeCtrl.SelectedItem

HTH
 
Beetee,
Thanks that did it!
I appreciate your help. You deserve a star.
 
No problem, romnew.

Now, personally, I could care less about stars. I have found that the threads I have put the most effort into, or provided the best answer, often go unstarred. Meanwhile, other threads, such as the one subverting the intrinsic Access security system, seems to get a lot of stars, when it really seems like a poor practice. I therefore consider the star process flawed. Not that it isn't good to see that someone appreciates the effort.

That being said, sometime you may post again and want to give someone a star. It turns out, you can do that, by clicking the 'Mark this post as a helpful/export post' link. You then have to affirm your request in a confirmation dialog, and the star is awarded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top