Problem displaying elements in a hierarchical Listbox

Hi,
I cannot increment the lines of my hierarchical ListBox. I have the same (last) row 6 times (or only the last row, if I set row = row +1).
and then can we know the total number of childrow elements stored?

In RowExpanded(row) event :

Var level As Integer = Me.RowDepthAt(row) + 1 // Indent level
For childRow As Integer = 0 To 5
  
// Get the row from RowTagAt
  Var line As String = Me.RowTagAt(childRow)
  
  // Divide the line into two parts before and after the ":"
  Var parts() As String = line.Split(":")
  
  // Check if the line contains at least two parts (before and after the ":")
  If parts.Ubound >= 1 Then
    Var key As String = parts(0).Trim
    Var value As String = parts(1).Trim
    
    // Add a new row to the hierarchical ListBox
    Window1.ListBox6.AddRow(key, value)
    'Me.RowTagAt(Me.LastAddedRowIndex) = level
  End if
  
  //Move to the next line using the next index
  'row = row + 1 ???
Next

Thanks a lot

Not 100% sure what you are doing here, but you iterate through Childrow 6 times
In each of them, you examine the same rowtag (Me.RowTagAt(row)) , split it, and then add the same details 6 times

Usually, the rowtag would contain a reference to some unique parent item - maybe a folder on disc or a database entry
Using that you then get a list of children of that thing, and add them.

You are also not doing anything with the rowdepth


Var level As Integer = Me.RowDepthAt(row) + 1

From the docs:

AddRowAt (row As Integer, text As String, depth As Integer = 0)
Creates a new row at row , moving the existing rows below row down. For multicolumn ListBoxes, text is always assigned to column zero. The optional parameter depth specifies the amount of indentation of the row in hierarchical ListBoxes. The default is zero. It has no effect on non-hierarchical ListBoxes.

Each RowTag contains a two-part character string that I display.

I correct my mistake with

Var line As String = Me.RowTagAt(childRow)

But it only returns one child item in the ListBox (the last one in the list).

The rowtag has 2 values separated by :
You split that, it’s one addable child.

Where is the data for ‘the other rows’?

You probably should read up very carefully about expandable rows in listboxes. When you expand a row, you have to create the newly visible rows yourself at that moment. “Hidden” rows are not hidden - they don’t exist.

1 Like

RowExpanded fires when you expand the parent row. The parent is designated by row. It us up to you to take the information from the parent and create the child rows. The only information you have to do so is what is stored in the parent.

So the question is, what is stored in the parent row and how can you use that to create the child rows?