List Property

       

Returns or sets the items contained in a control's list portion. The list is a string array in which each element is a list item. Available at design time for ListBox and ComboBox controls through the Properties window; read-only at run time for DirListBox, DriveListBox, and FileListBox controls; read/write at run time for ComboBox and ListBox controls.

Syntax

object.List(index) [= string]

The List property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index The number of a specific item in the list.
string A string expression specifying the list item.

Remarks

Use this property to access list items.

For all controls except the DirListBox, the index of the first item is 0 and the index of the last item is ListCount–1.

For a DirListBox control, the index number sequence is based on the current directories and subdirectories when the control is created at run time. The directory that is currently expanded is represented using the index–1. Directories above the currently expanded directory are represented by negative indexes with higher absolute values. For example,–2 is the parent directory of the directory that is currently expanded and–3 is the directory above that. Directories below the directory that is currently expanded range from 0 to ListCount–1.

Initially, ComboBox and ListBox controls contain an empty list. For the file-system controls, the list is based on conditions that exist when the control is created at run time:

The List property works in conjunction with the ListCount and ListIndex properties.

For all applicable controls except a DirListBox, enumerating a list from 0 to ListCount -1 returns all items in the list. For a DirListBox control, enumerating the list from–n to ListCount–1 returns a list containing all directories and subdirectories visible from the directory that is currently expanded. In this case n is the number of directory levels above the directory that is currently expanded.

Note   To specify items you want to display in a ComboBox or ListBox control, use the AddItem method. To remove items, use the RemoveItem method. To keep items in alphabetic order, set the control's Sorted property to True before adding items to the list.

Using an Option Base = 1 statement in the Declarations section doesn't affect the enumeration of elements in Visual Basic controls. The first element is always 0.

When the List index is outside the range of actual entries in the list box, a zero-length string ("") is returned. For example, List(-1) returns a zero-length string for a ComboBox or ListBox control.