Add Method (ListItems Collection)

       

Adds a ListItem object to a ListItems collection in a ListView control and returns a reference to the newly created object.

Syntax

object.Add(index, key, text, icon, smallIcon)

The Add method syntax has these parts:

Part Description
object Required. An object expression that evaluates to a ListItems collection.
index Optional. An integer specifying the position where you want to insert the ListItem. If no index is specified, the ListItem is added to the end of the ListItems collection.
key Optional. A unique string expression that can be used to access a member of the collection.
text Optional. A string that is associated with the ListItem object control.
icon Optional. An integer that sets the icon to be displayed from an ImageList control, when the ListView control is set to Icon view.
smallIcon Optional. An integer that sets the icon to be displayed from an ImageList control, when the ListView control is set to SmallIcon view.

Remarks

Before setting either the Icons or SmallIcons properties, you must first initialize them. You can do this at design time by specifying an ImageList object with the General tab of the ListView Control Properties dialog box, or at run time with the following code:

ListView1.Icons = ImageList1 'Assuming the Imagelist is ImageList1.
ListView1.SmallIcons = ImageList2 

If the list is not currently sorted, a ListItem object can be inserted in any position by using the index argument. If the list is sorted, the index argument is ignored and the ListItem object is inserted in the appropriate position based upon the sort order.

If index is not supplied, the ListItem object is added with an index that is equal to the number of ListItem objects in the collection + 1.

Use the Key property to reference a member of the ListItems collection if you expect the value of an object's Index property to change, such as by dynamically adding objects to or removing objects from the collection.