treeView Expand/Collapse problem

G

g

Hi,

I have a treeView in my form that works fine but I wanted to add an event
that nodes should expand one at a time. Meaning if 1 of the nodes selected
(HOSP1)it will expand the child nodes normally but if another nodes (HOSP2)
selected it should collapse the first nodes(HOSP1) selected automatically.

objTree.Nodes.Add , , "A", "Main Menu", "frame"

objTree.Nodes.Add "A", tvwChild, "A1", "HOSP1", "frame"
objTree.Nodes.Add "A1", tvwChild, "A21", "Add Record", "form"
objTree.Nodes("A21").Tag = "frmAdd"

objTree.Nodes.Add "A", tvwChild, "B1", "HOSP2", "frame"
objTree.Nodes.Add "B1", tvwChild, "B21", "Add Record", "form"
objTree.Nodes("B21").Tag = "frmAdd"

The reason I need this because I need to asign a value in main form
Me.MainForm.Site depending on what they selected HOSP1 or HOSP2.
If HOSP1 the site = 1 if HOSP 2 the site = 2.

Thank you
 
M

Michael Gramelspacher

Hi,

I have a treeView in my form that works fine but I wanted to add an event
that nodes should expand one at a time. Meaning if 1 of the nodes selected
(HOSP1)it will expand the child nodes normally but if another nodes (HOSP2)
selected it should collapse the first nodes(HOSP1) selected automatically.

objTree.Nodes.Add , , "A", "Main Menu", "frame"

objTree.Nodes.Add "A", tvwChild, "A1", "HOSP1", "frame"
objTree.Nodes.Add "A1", tvwChild, "A21", "Add Record", "form"
objTree.Nodes("A21").Tag = "frmAdd"

objTree.Nodes.Add "A", tvwChild, "B1", "HOSP2", "frame"
objTree.Nodes.Add "B1", tvwChild, "B21", "Add Record", "form"
objTree.Nodes("B21").Tag = "frmAdd"

The reason I need this because I need to asign a value in main form
Me.MainForm.Site depending on what they selected HOSP1 or HOSP2.
If HOSP1 the site = 1 if HOSP 2 the site = 2.

Thank you

I think that is controlled by the style selected in TreeCtrl Properties. Try select a different
style with Plus in the name.
 
G

g

Thanks but style is nothing to on what I need. My treeview has a plus at side
of each nodes title.

Any other suggestion??
 
M

Michael Gramelspacher

Meaning if 1 of the nodes selected

I am not sure what you need. If a node is expanded, the previously expanded node collapses.
Possibly if LineStyle is 0 it works this way. If you select a Style with PlussMinus, and LineStyle
is 1 you can control expanding and collapsing using the plus and minus.

Maybe someone else has something to add to help you.
 
R

Rob Parker

You can't set any of the treeview control's properties so that this happens
automatically. If you want it to happen, you need to use the Expand event
of the treeview control and include code to collapse the nodes which are
already expanded (excluding any node which is in the same branch of the tree
as the node you have just expanded).

Note also that the Expand event of the treeview control is not listed in the
Event tab of the property dialog box; you have to access it via the
combo-boxes in the Visual Basic editor - select the treeview control in the
left-hand combo, then the Expand event in the right-hand combo.

HTH,

Rob
 
G

g

Hi Rob,

So what would be the code to collapse the nodes which are already expanded?
I think of this already but I don't know the code to put in while you are in
expand event. Please help me on here.

Thank you Rob and also to Michael.
 
M

Manoj

Hi!!

on which event you will write this code? is it server side code or client
side code? if i want same thing through javascript what i have to do?
kindly guide me.
 
R

Rob Parker

This newsgroup is concerned with the Microsoft Access database software; the
code I posted for the previous question regarding the treeview control
applies to the Microsoft ActiveX component which is available in Access, and
is VBA (Visual Basic for Applications) code. The code snippet I posted
would be entered in the treeview control's Expand event (as I said in my
original post). Your question regarding server-side or client-side code is
meaningless in this context - it's code for a stand-alone application. I've
got no idea how you would do this in Javascript (and indeed, last time I
looked at Javascript, the language did not include a native treeview
control). This newsgroup is not the appropriate one for Javascript coding
questions, and sorry, I don't know of one which is. Try a Google search.

Rob
 
M

Manoj

Oh my mistake. I am trying this in web application that's why i was
discussing about server side and cliend side code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top