I would like to have only one node expanded at a time. Is it possible in code to collapse all open nodes before expanding a node? If so how. I’ve tried some code in listbox expandrow but have not been successful.
.
Closing open nodes can change the row clicked on, so it can be tricky, but I think it is doable. Complexity will depends on how many levels a node can have as well as if you care about sub levels being open.
This is off the top of my head.
In the simplest case where you only cate about the state of the top level nodes, Just keep track of the last top level node expanded in a private property (CurrentlyOpen as integer) that gets initialized to -1 and that gets set to -1 in CollapseRow.
In CellClick:
[code]If column > 0 OR X > 15 or CurrentlyOpen = -1 Or Row = CurrentlyOpen Or CurrentlyOpen > row then Return false
me.RowTag(Row) = True
me…expanded(CurrentlyOpen) = False
For row = me.ListCount-1 down to 0
if me.Rowtag(row).BooleanValue Then
me.Rowtag(row) = False
CurrentlyOpen = row
me.Expanded(row) = True
End if
Return True
[/code]
in CollapseRow:
If Row = CurrentlyOpen then CurrentlyOpen = -1
Wouldn’t a simpler option would be to run from clicked row down collapsing everything and then from the clicked row upwards collapsing? (skipping it in both cases, obviously)
Thanks Karen and Eduardo for your help. I used Eduardo’s suggestion.