Hierarchical Listboxes (RBL-0016)
If you want to write an outline tool, a file browser, or any other application that displays information as an organized hierarchy of text, REALbasic’s built-in Listbox control is a natural choice. Unfortunately, the built-in hierarchical Listbox control does not automatically handle expanding and collapsing rows when the user clicks on a folder. Plus, there is a gotcha when you go to insert a folder into an existing hierarchy: the InsertFolder method only adds folders at the top (leftmost) level of indentation. This tutorial will look at the built-in hierarchical controls and the approach suggested by the Online Language Reference. Then we’ll go beyond the docs and write a helper class that will make it much easier to handle expanding and collapsing rows, as well as insertions and deletions. The accompanying source code, HierList.rbp, will illustrate how to write a hierarchical Listbox that uses this helper class to cleanly and reliably implement a working hierarchical Listbox control.