ListBox.Selected

From Xojo Documentation

Property (As Boolean )
aListBox.Selected(Row as Integer) = newBooleanValue
or
BooleanValue = aListBox.Selected(Row as Integer)

Supported for all project types and targets.

Gets or sets the selection status of the passed Row. Row is zero-based.

Notes

Selected is True if the row passed is selected. This property can be used to determine if the row is selected and to select the row. For example,

Listbox1.Selected(1) = True //selects the second item in the first column.

Examples

Select Multiple Rows

In order to select multiple row, the SelectionType must be set to Multiple. This code selects only the even-numbered rows:

ListBox1.ListIndex = -1 // Deselect all rows

For i As Integer = 0 To ListBox1.ListCount - 1
If i Mod 2 = 0 Then
ListBox1.Selected(i) = True
End If
Next

Getting the list of selected rows

If you allow the ListBox to have multiple items selected (see SelectionType), you may want to establish a list of all the rows selected. The following example shows how to achieve that. The ListBox is named ListBox1.

Dim selectedRows() As Integer // Will hold the index of each selected row

For row As Integer = 0 To ListBox1.ListCount - 1 // Rows are zero-based
If ListBox1.Selected(row) Then
selectedRows.Append(row) // This row is selected
End If
Next