# Two level heirarchical listbox example?

**URL:** <https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912>\
**Category:** macOS\
**Created:** [June 13, 2015, 2:21pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912 "2015-06-13T14:21:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 2:21pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/1 "2015-06-13T14:21:01Z")

</div>

Hi,  
does anyone know if there is an example anywhere of how to create a hierarchical listbox for OS X?

Thank you all in advance.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 2:25pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/2 "2015-06-13T14:25:05Z")

</div>

Did you into examples included with Xojo?

---

<div class="post-metadata">

**Author:** ![Axel\_Schneider](https://forum.xojo.com/user_avatar/forum.xojo.com/axel_schneider/32/465_2.png) [@Axel\_Schneider](https://forum.xojo.com/u/Axel_Schneider)\
**Post date:** [June 13, 2015, 2:25pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/3 "2015-06-13T14:25:43Z")

</div>

/Example Projects/Desktop/Controls/ListBox/FileBrowser.xojo\_binary\_project

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 2:27pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/4 "2015-06-13T14:27:09Z")

</div>

Thanks Christian / Axel.  
I think I must have delete some example folders, as I looked there first of all, but they didn’t exist?

I have just re-downloaded them, and now have them 🙂

Thanks.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 3:49pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/5 "2015-06-13T15:49:33Z")

</div>

OK - this has me puzzled:

I have created a new project file, and dragged in a Listbox which is set to hierarchical.

I can add this code in the Listbox.open event - which successfully creates 2 Main Folders:

`Me.AddFolder"Folder1"
Me.AddFolder"Folder2"`

Is there a relatively simple way to now add 2 sub folders to each of these, and then add 2 normal rows to each of these 2 subfolders?

I’m sure this is probably ridiculously simple, but I’m staring at it, and nothing makes any sense ☹

Any help appreciated.  
Thank you all in advance.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 5:04pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/6 "2015-06-13T17:04:48Z")

</div>

normally you get sub rows using Expand event. You can expand them in code by setting expanded(row) property.  
Or you check the indent parameter for InsertFolder/InsertRow methods.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 8:42pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/7 "2015-06-13T20:42:25Z")

</div>

Thanks Christian, but I still cannot work out how to do this ☹

Does anyone by chance have an example project which simply shows how to have a TWO level hierarchical listbox?  
I can then spend hours looking at the code, and work out what is happening.

I simply need a hierarchical listbox, which has main folders, which each contain 1 subfolder which in turn contains 1 normal row inside it.

The examples I have found, either contain just 1 folder containing rows (which I can already do), OR, multi level folders which are so complex that I cannot understand them.

Hence why I am looking for an example which has main folders \> sub folder \> row

Hopefully someone is able to help.  
Thank you all in advance for any help you can offer.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 8:45pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/8 "2015-06-13T20:45:12Z")

</div>

Why not simply add code in Expand event to add rows?  
They will have right indent.  
And you can toggle expanding with list.expanded(row) = true

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 8:46pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/9 "2015-06-13T20:46:13Z")

</div>

Christian,  
I need main folders, with sub folders, with rows.

I cannot add code to the expand event, as I have no idea what I am doing ☹

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 8:46pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/10 "2015-06-13T20:46:32Z")

</div>

and how do you have your data structured?

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 8:47pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/11 "2015-06-13T20:47:37Z")

</div>

I used the example single level hierarchical listbox from the Language Reference - but this only shows single level, and I need 2 level.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 8:48pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/12 "2015-06-13T20:48:16Z")

</div>

put a listbox on your window and put this code in open event:

[code] Listbox1.Hierarchical = true  
Listbox1.InsertRow 0,“Hello World 1”  
Listbox1.InsertRow 1,“Hello World 2”,1  
Listbox1.InsertRow 2,“Hello World 3”  
Listbox1.InsertRow 3,“Hello World 4”,1  
Listbox1.InsertRow 4,“Hello World 5”

[/code]

That fills the hierarchical listbox right away with indent.  
You can of course use InsetFolder have the triangle.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 8:51pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/13 "2015-06-13T20:51:09Z")

</div>

Christian,  
Thanks but I already have a fully working single level hierarchical listbox - whereby the user clicks on the disclosure triangle in order to display the row.

I need a top level folder, which when expanded, displays a sub folder, which when expanded shows a row.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 9:51pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/14 "2015-06-13T21:51:16Z")

</div>

no, this is two level already!?

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 9:56pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/15 "2015-06-13T21:56:56Z")

</div>

The LR example is described as single level hierarchical, therefore I need a 2 level.  
If you are saying that a row in a folder, in another folder is 3 levels, then I need a 3 level.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [June 13, 2015, 9:58pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/16 "2015-06-13T21:58:23Z")

</div>

well, make a new project with a listbox and put code in open event:

` listbox1.Hierarchical = true
  listbox1.AddFolder "Hello"
  listbox1.Expanded(Listbox1.LastIndex) = true`

than add an ExpandRow event to the listbox with this code:

```auto
me.AddRow "Hello World"
```

run it and you see a listbox with two levels, the folder and the item inside.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 10:01pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/17 "2015-06-13T22:01:34Z")

</div>

Christian,  
once again - I already have that.

The Language Reference describes that as SINGLE level?  
I need another level. Two folders and a row.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [June 13, 2015, 10:30pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/18 "2015-06-13T22:30:24Z")

</div>

Richard, try this example I just put together in a few seconds. Basically you add another folder in the Expand event, or just add normal rows. You should have a class that describes the data model you are representing in the listbox and it should make this pretty easy.

[https://www.dropbox.com/s/zkp24ppu3i0vi1u/expand%20row%20listbox.xojo\_binary\_project?dl=0](https://www.dropbox.com/s/zkp24ppu3i0vi1u/expand%20row%20listbox.xojo_binary_project?dl=0)

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [June 13, 2015, 10:46pm UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/19 "2015-06-13T22:46:41Z")

</div>

Thanks Jason.  
I will take a look after a cup of tea. This is giving me a real headache ☹

---

<div class="post-metadata">

**Author:** ![Harrie\_Westphal](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Harrie\_Westphal](https://forum.xojo.com/u/Harrie_Westphal)\
**Post date:** [June 14, 2015, 12:09am UTC](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912/20 "2015-06-14T00:09:02Z")

</div>

Richard, have you looked at the FileBrowser example that comes with Xojo. You can find it along the path Desktop/Controls/Listbox/FileBrowser.xojo\_binary\_project. It allows you to browse the contents of a hard drive. I quite after getting about 10 levels deep. If you can’t figure it out with that example you may never figure it out. 😉

[Next page](https://forum.xojo.com/t/two-level-heirarchical-listbox-example/24912.md?page=2)
