Adding Items and Subitems

Each item in a list view control has an icon, a label, a current state, and an application-defined value. By using list view messages, you can add, modify, and delete items as well as retrieve item data. You can also find items with specific attributes.

Each item can also have one or more subitem. A subitem is a string that, in report view, is displayed in a column to the right of an item's icon and label. To specify the text of a subitem, use the LVM_SETITEMTEXT or LVM_SETITEM message. All items in a list view control have the same number of subitems. The number of subitems is determined by the number of columns in the list view control.

The LVITEM structure defines a list view item or subitem. To add an item to a list view control, use the LVM_INSERTITEM message. Before adding multiple items, you can send the control an LVM_SETITEMCOUNT message to specify the number of items the control will ultimately contain. This message enables the list view control to reallocate its internal data structures only once rather than every time you add an item. Determine the number of items in a list view control by using the LVM_GETITEMCOUNT message.

Use the LVM_SETITEM message to change the attributes of a list view item. The LVM_SETITEMTEXT message changes only the text of an item or subitem.

To retrieve list view item data, use the LVM_GETITEM message specifying the address of the LVITEM structure to fill. To retrieve only an item or subitem's text, use the LVM_GETITEMTEXT message. To delete a list view item, use the LVM_DELETEITEM message. Delete all items in a list view control by using the LVM_DELETEALLITEMS message.