From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

DesktopListBox.AddRow(ParamArray Item as String)

Supported for all project types and targets.

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.


DesktopListBox.AddRow(items() as String)

New in 2021r3

Supported for all project types and targets.

Appends a new row to the end of the list with each element of Item as a separate column.



New in 2021r3

Supported for all project types and targets.

Appends a new blank row to the end of the list.


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:

Var v As Variant = "Hello"


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:

ListBox1.SelectedRowIndex = ListBox1.LastAddedRowIndex

Or you can manually scroll the ListBox to the right position:

ListBox1.ScrollPosition = ListBox1.LastAddedRowIndex


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.

ListBox1.Visible = False
// Do long running AddRow code here
ListBox1.Visible = True


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:

Listbox1.AddRow("Sept", "Oct", "Nov", "Dec")

The following line adds a row of months to a ListBox that has four columns using an array:

Var months() As String = Array("Sept", "Oct", "Nov", "Dec")

The following adds a blank row then sets values for column 3:

ListBox1.CellTextAt(ListBox1.LastAddedRowIndex, 2) = "Col 3"

See Also

DesktopListBox.AddFolder and DesktopListBox.AddRowAt methods