ListBox.AddRow
From Xojo Documentation
Appends Item in a new row to the end of the list. Because it is called ParamArray, you can pass several items for a multicolumn ListBox. The items are separated by commas and will be the values for the various columns.
Appends a new row to the end of the list with each element of Item as a separate column.
Appends a new blank row to the end of the list.
Notes
Use LastAddedRowIndex to determine the last row added. In the case of hierarchical ListBoxes, AddRow appends Item to the subitems of the expanded row when called in the ExpandRow event. The theoretical maximum number of rows is over 2 billion but the actual number will be lower due to memory constraints.
Variant Usage
Note that you get a compile error if you pass a Variant to AddRow methods. When using a Variant, convert it first to string or array so the compiler knows which method you want to call:
Scrolling
If you are adding many rows to the ListBox, eventually the results will scroll off the bottom of the ListBox and no longer be visible. To make a newly added row visible, you have to scroll the listbox to the location of the newly added row. You can do this by setting the SelectedRowIndex property to the value of the newly added row like this:
Or you can manually scroll the ListBox to the right position:
Performance
Populating ListBoxes with data is a common task. If you are filling a ListBox with lots of data (which itself may not be a great idea), you can first make the ListBox invisible before you add the rows and then make it visible after the rows have been added. This can prevent some unnecessary possible screen refreshes and resulting event calls, providing an overall speed improvement.
Overriding
If you need to override AddRow, override the second version with items array. This is the main method which is called by the others.
Sample Code
Adding the string "October" to a new row in a ListBox named Listbox1:
The following line adds a row of months to a ListBox that has four columns:
The following line adds a row of months to a ListBox that has four columns using an array:
The following adds a blank row then sets values for column 3:
ListBox1.CellValueAt(ListBox1.LastAddedRowIndex, 2) = "Col 3"
See Also
ListBox.AddFolder and ListBox.AddRowAt methods