Two level heirarchical listbox example?

I guess I will never figure it out then, because that example was totally inappropriate for my requirements :frowning:

Thanks anyway.

You might also want to check the actual ListBox example projects here:

Examples/Desktop/Controls/ListBox

Also, there are a couple webinars that cover several of those examples:

Richard, what is the data structure you want to show in the listbox? I mean is it from a database or a couple objects of arrays or an array of objects with arrays or
?

I ask because I’ve done hierachical listboxes many times and find it very easy when the structure of my data actually matches the hierachy to show. That’s basically a tree of objects where each object/node is to be a row.

The trick is to store the object representing the row in the RowTag. This way, in the ExpandRows event you just grab the object being expanded from the RowTag and add it’s children as new rows.

There’s may ways to implement this, what’s going to work best depends on where your new row info is coming from, but in general, using the RowTag to store an id or object from which you can gather and build the new child rows has made hierarchical listboxes very easy for me.

I haven’t looked but I imagine this is what the FileBrowser example does: put the actual Folderitem a row represents into the RowTag. Then in ExpandRow it gets this Folderitem and adds its children by adding a row for each child and setting the RowTag to that child.

this article on rblibrary.com comes with an example project which shows a mulit-level hierarchical listbox:
http://great-white-software.com/rblibrary/index.php?main_page=product_info&cPath=15&products_id=64

Thanks Oliver - I will take a look.

[quote=194201:@Richard Summers] if you look in the ExpandRow event, you will notice that the number of possible combinations for the row’s ListIndex increases dramatically for each sub folder.

I need a way to drastically shorten this somehow?[/quote]
What’s happening is the structure of data you’re trying to show doesn’t exist. So in the ExpandRows event it has to go through all kinds of gymnastics to re-work out what the next part of the structure is.

For a single-level/flat listbox it’s usually enough to just use it as your data structure, no need for something else. This is because a flat listbox is basically a single array, it can represent all of the structure.

But for a hierachical listbox you’re not seeing the whole thing, collapsed folders need to show new data not already there. Since a hierarchical listbox is a tree structure the easiest thing to do is to have that tree someplace. Then there’s a one to one coorespondence between nodes of your tree and rows in the listbox.

Almost always when I start building a hierarchical listbox I already have a data structure in tree form. I mean if your data is supposed to represent some tree structure it’s usually natural to build it that way. So first should come your data model in tree form.

Then all you have to do for a hierachical listbox is store the node for a row in the RowTag. In ExpandRow the task is simply to get this node and add its children to the listbox.

Now, I say simply but there’s many ways to implement ‘adding children’, and your well-designed data structure source may not be in 1:1 coorespondence with the intended listbox tree view.

Skipping all those complications this is what I did in the example

Make a class to represent nodes of your tree.
On Open (or someplace appropriate) build the actual tree structure.
Anytime you add a row also set the RowTag to that node.
In ExpandRows get that node and add its children as rows, again with RowTag as the node.

I added a couple convenience methods on the node class to make adding and expanding easier (lbAdd and lbExpand) but I also included code to do it manually.

http://home.comcast.net/~trochoid/expandrowlistbox-3.xojo_binary_project.zip

Thanks Will - very much appreciated.
I’m sure with the advice and examples yourself and others have given, that I will be able to comfortably use hierarchical list boxes in the future :slight_smile:

Once again - thank you all!