How do I add a folder and then add a row with a listbox. I presume I am meant to use InsertRow but how do I know the index of the last inserted folder. Is there something like this in the docs other than the one that uses NthField.
I see this:
Hierarchical ListBoxesCreating a simple hierarchical ListBox is more involved than a two-column ListBox because you must manage hiding and displaying the sublist data. A simple way to do this is to assign the sublists to a “hidden” column in the ListBox and toggle the display of that data when the user double-clicks on a “parent” element.
You create a row with a disclosure triangle using the AddFolder method (rather than the AddRow method) and then set the Hierarchical property to True. See the Example for a simple hierarchical ListBox with one level.
From Xojo docs
Is there an API that makes what I am trying to achieve more convenient or am I underestimating the convenience of the technique above.
You add rows to a folder in the ExpandRow event. If you need to do that explicitly, set the Expanded property to True and the ExpandRow event will fire:
Once you do as Greg suggests, you don’t need to worry about the index. Within the ExpandRow event, AddRow and AddFolder will add the next row to the folder that was expanded.
dim index as uint32 = row
//comparing if indexed row has a higher indent than the collapsed row
while me.RowTag(index) > me.RowTag(row)
row = row + 1
me.RemoveRow(index)
wend
All seems good.
[quote=93069:@Greg O’Lone]You add rows to a folder in the ExpandRow event. If you need to do that explicitly, set the Expanded property to True and the ExpandRow event will fire:
Well, that does work, but that’s not what I recommended. As I posted, use AddRow, not InsertRow, and they will be added as subrows to the main folder row, indents and all. And you won’t need the code in CollapseRow either as that will be taken care of for you.