Toggle Hierarchical Listbox

I have a hierarchical listbox where EXPANDROW updates the items it displays based on actions taken by the user. These actions may cause items to be added or deleted from a particular “branch”.

If I manually toggle the listbox row, collapsing, and re-expanding the new data appears…

What I am trying to do is cause this to happen when the user action occurs

  For i=lb.ListCount-1 DownTo 0
    If lb.Expanded(i) Then 
      lb.Expanded(i)=False
      lb.Expanded(i)=True
    End If
  Next i

This is called each time something is added or deleted, HOWEVER, the end result is row that was changed remains collapsed…

I have code that does that for a single row and it works… (it’s easier to close , sort the children when the new child is added and then open the level, that figure out where to use - particularly when one is using lined to show the tree relationships)

Is you try it on a single row just to see if that worlds as expected for you?

  • Karen

The problem is the amount of “code”/“time” it would take to figure exactly where on the list the new item goes is more complex than just toggling any expanded branch…

The interesting thing is in my testing… I have 3 expanded…

Section -> SubSection-> Items

If SECTION and SUBSECTION are expanded showing the list of items… and I execute the above code…
SECTION remains expanded… but SUBSECTION closes

But if I do send it a key to id the row, and it then seems to work…

Multiple levels… If I understand then In the expand event to have to have code to expand the sub levels . I have code to do that in my listbox subclass

  • karen

[quote=161833:@Dave S]If SECTION and SUBSECTION are expanded showing the list of items… and I execute the above code…
SECTION remains expanded… but SUBSECTION closes[/quote]
Because you’re walking the tree backwards, you encounter the subsection first, close it and open it, which redisplays the items. Next you enounter the section. When you close it it removes all the subsections and items. Then when you open it again, it adds back only the subsections.

I tried it both directions… same result… but if I pass a key to id ONE row to collapse/expand it works.