Hierarchical Listbox

Does anyone have a very simple example of using the listbox as a hierarchical listbox? I.e. one folder and one subitem. I am finding the file browser example in the xojo examples rather hard to follow and I cant find anything in the docs.

Thanks

in Listbox1.Open Put

Me.AddFolder "A Folder"

In Listbox1.ExpandRow do:

me.AddRow "A Child"

Run and click on disclosure widget

Make sure you set the listbox to Hierarchical of course

Have you looked at the Listbox example?

Examples/Desktop/Controls/ListBoxExample

[quote=69043:@Paul Lefebvre]Have you looked at the Listbox example?

Examples/Desktop/Controls/ListBoxExample[/quote]

Paul,

Any chance of doing a JSONItem version of hierarchical listbox?

Did you try it yourself? Great learning exercise.

I had a quick glance at the docs…but haven’t tried it yet.

It could also make a great Webinar topic.

I’ll be covering JSONItem in “Fun with Files” on April 8. I already did a webinar on ListBoxes, including hierarchical.

Combining the two is an exercise for the viewer. :slight_smile:

Oh well…I can’t wait for the webinar :slight_smile:

Paul, where would I find that. I only have the following path /Applications/Developer/Xojo 2013 Release 2/Example Projects/Desktop which does not contain a ListBoxExample project

It is available starting with Xojo 2013 Release 3.

Oh well I will suss it out. Not upgrading my licence to get it working :wink:

[quote=69036:@Karen Atkocius]in Listbox1.Open Put

Me.AddFolder “A Folder”
In Listbox1.ExpandRow do:

me.AddRow “A Child”
Run and click on disclosure widget[/quote]
Thanks Karen, that has got me started. So I can’t load them all up in the open event then. What I was wanting to do was something like:

Listbox1.AddFolder("Folder1") Listbox1AddRow("Item in Folder 1") Listbox1AddRow("Item in Folder 1") Listbox1AddRow("Item in Folder 1") Listbox1AddRow("Item in Folder 1") Listbox1.AddFolder("Folder2") Listbox1AddRow("Item in Folder 2") Listbox1AddRow("Item in Folder 2") Listbox1AddRow("Item in Folder 2") Listbox1AddRow("Item in Folder 2")

try the example in the language reference http://documentation.xojo.com/index.php/Listbox

You can certainly grab the free version to try out the example. It ought to work in r2 as well.

Thanks Kuzey, that was what I was looking for.

Thanks Paul - I used the example Kuzey suggested above on the Xojo website.

I must say this seems a little haphazard in the way it is done. Wouldn’t it have been easier (for the developer) to have something along the lines of:

ListBox1.AddItem(“MyItemCaption” , “MyItemKey”)
ListBox1.Item(“MyItemKey”).AddSubItem(“MySubItemCaption” , “MySubItemKey”)

Hierarchical listbox can be alternately seen as “spartan” or “lean and mean”, depending on your point of view. The key point to note is that the sub items do not have an independent existence other than whatever mechanism you devise. That is both the power and the shortcoming of the listbox (again, depending on your pov). Subitems are created brand new every time the folder is expanded and deleted completely when the folder is collapsed. They don’t exist until you create them in the expandrow event. You must

  • examine the row being expanded
  • determine what the child rows should be
  • create them fresh via addfolder/addrow

The listbox doesn’t keep track of any of that for you.

The design of the listbox makes it extremely flexible. Anything more specific would make it less so IMO.