Syntax
listview.ListItems
listview.ListItems(index)
The syntax lines above refer to the collection and to individual elements in the collection, respectively, according to the standard collection syntax.
The ListItem object, ListItems collection syntax has these parts:
Part | Description |
listview | An object expression that evaluates to a ListView control. |
index | Either an integer or string that uniquely identifies a member of a ListItem collection. The integer is the value of the Index property; the string is the value of the Key property. |
Remarks
ListItem objects can contain both text and pictures. However, to use pictures, you must reference an ImageList control using the Icons and SmallIcons properties.
You can also change the image by using the Icon or SmallIcon property.
The following example shows how to add ColumnHeaders and several ListItem objects with subitems to a ListView control.
Private Sub Form_Load()
Dim clmX As ColumnHeader
Dim itmX As ListItem
Dim i As Integer
For i = 1 To 3
Set clmX = ListView1.ColumnHeaders.Add()
clmX.Text = "Col" & i
Next i
' Add 10 items to list, all with the same icon
For i = 1 To 10
Set itmX = ListView1.ListItems.Add()
itmX.SmallIcon = 1
itmX.Text = "ListItem " & i
itmX.SubItems(1) = "Subitem 1"
itmX.SubItems(2) = "Subitem 2"
Next i
End Sub