DesktopListBox.AddRows

From Xojo Documentation

Method

DesktopListBox.AddRows(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 causing each item to be the value for a new row.


Method

DesktopListBox.AddRows(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 row.


Method

DesktopListBox.AddRows(rows As RowSet)

New in 2021r3

Supported for all project types and targets.

Appends rows from the RowSet to the ListBox. If the ListBox does not have enough columns, more columns will be added.

Notes

Use LastAddedRowIndex to determine the last row added. In the case of hierarchical ListBoxes, AddRows appends Item to the subitems of the expanded row when called in the RowExpanded 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 the AllAllRows method. 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"
ListBox1.AddAllRows(v.StringValue)

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:

ListBox1.SelectedRowIndex = ListBox1.LastAddedRowIndex

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

ListBox1.ScrollPosition = ListBox1.LastAddedRowIndex

Overriding

If you need to override AddRows, override the second version with items array. This is the main method which is called by the others.

Sample Code

The following line adds rows of months to a ListBox:

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

The following line adds rows of months to a ListBox using an array:

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

See Also

DesktopListBox.AddExpandableRow and DesktopListBox.AddRow methods