The overall appearance of a ListView is determined by the View property. The
View property can have one of the following four values:
ListItems are inserted into a ListView by using
the Add method.
The Add method has the following syntax:
ListView1.ListItems.Add(index, key, text, icon,
All the arguments for the Add method are optional.
The Index argument is an integer value that you
can use to specify the position of the new item
being added to the list. If the Index argument
is omitted, Visual Basic places the new item at
the end of the list.
The Key property is a unique string that you
can use to identify an item in the list instead
of using the Index to that object.
The last three arguments—Text, Icon, and
SmallIcon—determine the appearance of the
new item in the ListView.
If the Text argument is given, that text will
appear with the item in the ListView.
The Icon and SmallIcon arguments are integers
referring to an icon in an ImageList control.
As with the TreeView, the ListView needs at least
one ImageList control on the form for icons to
References to ImageLists are set through the Property Pages dialog box for
the ListView, as shown in Figure 4.8. You can set references to two different
ImageLists for a ListView: one reference for regular icons (when the ListView's
View property is lvwIcon) and a second list for small icons (when the View property
is set to any other value).
Because an ImageList control can only contain
images of a single size, two ImageLists are required
if you will be using both regular and small icons.
Typically regular icons will be 32X32, and small
icons will be 16X16.
FIGURE 4.8 Setting an ImageList reference for a ListView control.
ListView Control topics