List Property

Applies To

ComboBox control, ListBox control.

Description

Returns or sets the list entries of a ListBox or ComboBox.

Syntax

object.List( row, column ) [= Variant]

The List property syntax has these parts:

Part

Description

object

Required. A valid object.

row

Required. An integer with a range from 0 to one less than the number of entries in the list.

column

Required. An integer with a range from 0 to one less than the number of columns.

Variant

Optional. The contents of the specified entry in the ListBox or ComboBox.


Settings

Row and column numbering begins with zero. That is, the row number of the first row in the list is zero; the column number of the first column is zero. The number of the second row or column is 1, and so on.

Remarks

The List property works with the ListCount and ListIndex properties. Use List to access list items. A list is a variant array; each item in the list has a row number and a column number.

Initially, ComboBox and ListBox contain an empty list.

Note To specify items you want to display in a ComboBox or ListBox, use the AddItem method. To remove items, use the RemoveItem method.

Use List to copy an entire two-dimensional array of values to a control. Use AddItem to load a one-dimensional array or to load an individual element.

See Also

AddItem method, Column property, ListCount property, ListIndex property, RemoveItem method.

Example

The following example swaps columns of a multicolumn ListBox. The sample uses the List property in two ways:

  1. To access and exchange individual values in the ListBox. In this usage, List has subscripts to designate the row and column of a specified value.
  2. To initially load the ListBox with values from an array. In this usage, List has no subscripts.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains a ListBox named ListBox1 and a CommandButton named CommandButton1.

Dim MyArray(6, 3)           'Array containing column values for ListBox.

Private Sub UserForm_Initialize()
    Dim i As Single

    ListBox1.ColumnCount = 3        'This list box contains 3 data columns

    'Load integer values MyArray
    For i = 0 To 5
        MyArray(i, 0) = i
        MyArray(i, 1) = Rnd
        MyArray(i, 2) = Rnd
    Next i

    'Load ListBox1
    ListBox1.List() = MyArray

End Sub

Private Sub CommandButton1_Click()
'Exchange contents of columns 1 and 3

    Dim i As Single
    Dim Temp As Single

    For i = 0 To 5
        Temp = ListBox1.List(i, 0)
        ListBox1.List(i, 0) = ListBox1.List(i, 2)
        ListBox1.List(i, 2) = Temp
    Next i
End Sub