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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to have TreeView nodes collapse on open

Status
Not open for further replies.

at51178

Technical User
Mar 25, 2002
587
US
Hi

I have been looking all over the web for this answer which I believe should be easy to answer

How do I get my Treeview nodes to expand when a form opens.
 
set lower nodes to node.ensurevisible to expand
 
You're not the vonly one that's frustrated over the lack of available Help on the TreeView control at51178 .

There's lots of things I think this control aught to be able to do - if only I knew where to look for the source info.

anyway
I've tried gol4's suggestion using

CRDisplay.Nodes.Add hld.Name, tvwChild, fld.Name, fld.Name
CRDisplay.Node.EnsureVisible

The first line is working fine
hld.Name is the Holder folder in a file structure on the network
fld.Name is a sub folder in the hld.Name

So the Tree biulds up an image of the folder tree structure with files being the leaves at the end.

But I still can't get the thing to auto expand.

Whats missing in the above ?






G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Google was one of my most valauble resources in learning the treeview but my most valuable was my F2 key

the object browser has all the methods etc.. you need to learn the treeview.

for the node you need to tell it which node you want
heres an example to expand all the nodes

dim treenode as node
for each treenode in treeview1.nodes
if treenode.expanded = false then
treenode.ensurevisible
end if
next

good luck
 
I use something like this to add expanded nodes.
Code:
         Set nod = .Nodes.Add(Key:=strNode1Text, _
            Text:="RecID", Image:=1)
         'Expand the entire node
         nod.Expanded = True

HTH,
Eric


 
Well that's a real 'teach a man to fish" moment gol4

I've been hitting the F1 key and getting totally frustrated by the lack of info - and it was next door all the time!


Thanks





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Hi

I have tried all your suggestions but for some reason it does not work, this is what I am using. but I get a run-time error 438
Object doesn't support this property or method

'Node Level 3
Set rs = db.OpenRecordset("Nod1", dbOpenDynaset)
Do Until rs.EOF
Me!axtreeview.Nodes.Add rs!Nod.Value, tvwChild, rs!Nod1, rs!Nod1
Me.axtreeview.Node.EnsureVisible
rs.MoveNext
Loop
rs.Close
 
Yes - you're doing what I said doesn't work


Mod your code to


'Node Level 3
Dim nodNew As Node
Set rs = db.OpenRecordset("Nod1", dbOpenDynaset)
Do Until rs.EOF
Set nodNew = axtreeview.Nodes.Add rs!Nod.Value, tvwChild, rs!Nod1, rs!Nod1
nodNew.Expanded = True
rs.MoveNext
Loop
rs.Close

G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Nice Job LittleSmudge you have gone from treeview student to teacher in one thread. :)

What I should have explained in more detail and will hopely clear it up for you at51178 is that each node is a collection of the treeviews nodes. So to set a nodes property you need refer to that node to set its property.
Me.axtreeview.Nodes(22).EnsureVisible would work
but not
Me.axtreeview.Node.EnsureVisible

the examples posted by LittleSmudge and Eric above are the proper way to load the treeview so you can track the current node

I personally don't like to expand all the nodes so using the ensurevisible will expand the particular node I want and scroll to it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top