List Box - AddRowAt

Hi,
On my example, I have 2 column listbox.
I want to add new entry in top of the list box, so I used AddRowAt method.
But I cannot pass the 2 column values.
From document I get this one
For multicolumn ListBoxes, text is always assigned to column zero. Can anyone help how to pass 2 column value in AddRowAt method.

After adding the row and column zero, use CellTextAt to set the other columns.

It’s funny that AddRowAt doesn’t accept a paramarray like AddRow does.

2 Likes

Laughs in Xojo

2 Likes

Add this extension method to a module:

Public Sub AddRowAt(extends lb as Listbox, RowNumber as Integer, ParamArray str() as String)
  
  Dim columnCount As Integer = lb.ColumnCount
  Dim ValuesToInsertCount As Integer = Str.LastIndex + 1
  
  Select Case True
    
  Case columnCount = ValuesToInsertCount 
    lb.AddRow(Str(0)) // first column
    Dim row As Integer = lb.LastAddedRowIndex
    For col As Integer = 1 To Str.LastIndex
      lb.CellValueAt(row, col) = Str(col)
    Next
    
  Case columnCount > ValuesToInsertCount 
     MessageBox "There are not enough values for all columns to be filled. Do you want to proceed?"
    
  Case columnCount < ValuesToInsertCount
    MessageBox "There are not enough columns for all values to be inserted. Do you want to proceed and discard the extra values?"
    
  Else
    MessageBox "Now I've seen everything … I'm going home."
    
  End Select
  
End Sub

Call it like this

Listbox1.AddRowAt(5, "a", "b", "c", "d")
4 Likes