I wanted to use 2 for next loops to put the category in the expandable row and the record(s) underneath each category ,as a test I just wanted to use two loops to give me a hierarchical list, but I must be doing something wrong… I took the code from the listbox hierarchical list example, but this does not work. I do not know what I am doing wrong. It should be easy to add as many child (nodes?) as you need. imoho.
for i as integer = 0 to Categories.Count-1
me.AddExpandableRow(i.ToText + ". " + Categories(i).ToText)
dim z as integer
for z = 0 to Categories.Count-1
Me.AddExpandableRowAt( i,i.ToText + "— " + Categories(z).ToText,1)
next z
// // try loading categories and displaying records under the category
You don’t do it all at the beginning. Just add the rows that will be visible when the app starts. For any expandable row, use AddExpandableRow to add it. If you want to have that row be expanded , you need to set its RowExpandedAt property to be True.
You do all remaining work in the ExpandRow event handler which will fire when you set the RowExpandedAt property to True.
The code to add the expandable rows would go in the Open event (or wherever you wish to begin adding them) and then when the user expands a row, the code that adds rows to that level of the hierarchy goes in the ExpandRow event. Paste in this code to see what I mean:
ListBox Open Event:
Var Sports(2) As String
Sports(0) = "Baseball"
Sports(1) = "Football"
Sports(2) = "Hockey"
For Each sport As String In Sports
Me.AddExpandableRow(sport)
next
ListBox ExpandRow Event:
Var sport As String = Me.CellValueAt(row, 0)
Select Case sport
Case "Baseball"
Me.AddRow("The Dodgers")
Me.AddRow("The Mets")
Me.addrow("The Rangers")
Case "Football"
Me.AddRow("The 49ers")
Me.AddRow("The Raiders")
Me.AddRow("The Rams")
Case "Hockey"
Me.AddRow("The Blackhawks")
Me.AddRow("The Hurricanes")
Me.AddRow("The Kings")
End Select
You can programmatically expand rows using the RowExpandedAt property: