ListBox - Expand All

I have a desktop app with a hierarchal ListBox (disclosure triangles / +) to expand the indented row below it.

Is there any way to expand all of the rows without having to repeatedly loop and walk the list to expand every unexpanded row until there are no more to be expanded?

No, but what’s wrong with that method? Just be sure to start from the bottom and work up.

For expanding you want to work down :slight_smile:

And make it an extension method so it’s available on all listboxes.

The only issue with looping through a ListBox with lots of entries is the amount of time.

Ah, yes. That is, unless you only want the top level expanded.

For a reasonalble # of rows, speed should not be an issue.

If you have THAT many entries, perhaps the UI needs to be rethought?

BTW I provide that on my listbox subclass, I also provide a way to expand the subtree for a specific node, and use it when the user option-clicks on the disclosure widget.

That seems something that the listbox should support out of the box.

Kem, I think Will is correct on this one. Expanded rows are added after the current row. Working bottom up, you’d miss the newly expanded rows.

Yup, I got that. So if you want to recursively expand, work top-down. But if you only want the first level expanded, word bottom-up so it doesn’t enter the newly-expanded rows. Or did I miss something?

Personally, I prefer using the Einhugur TreeView control for things like this. You can lock the drawing while building the list and set whether or not it’s expanded during that time. Since all the nodes are memory persistent you can load once and forget. I also think it looks better but that’s just my opinion. It doesn’t have as many buzzers and bells as the built-in listbox so it really does depend on what features you need.

I read the OP as requesting just that: all rows expanded until there are no more to expand, ie., recursively. I see how it might be ambiguous, though.