Share via


List Items and Image Lists

OverviewSample

An "item" in a list control () consists of an icon, a label, and possibly other information (in "subitems").

The icons for list control items are contained in image lists. One image list contains full-sized icons used in icon view. A second, optional, image list contains smaller versions of the same icons for use in other views of the control. A third optional list contains "state" images, such as check boxes, for display in front of the small icons in certain views. A fourth optional list contains images that are displayed in individual header items of the list control.

Note   If a list view control is created with the LVS_SHAREIMAGELISTS style, you are responsible for destroying the image lists when they are no longer in use. Specify this style if you assign the same image lists to multiple list view controls; otherwise, more than one control might try to destroy the same image list.

For more information about list items, see and in the Platform SDK. Also see class in the Class Library Reference and Using CImageList in this article.

To create a list control, you need to supply image lists to be used when you insert new items into the list. The following example demonstrates this procedure, where m_pImagelist is a pointer of type CImageList and m_listctrl is a CListCtrl data member.

// create, initialize, and hook up image list
m_pImageList = new CImageList();
ASSERT(m_pImageList != NULL);    // serious allocation failure checking
m_pImageList->Create(32, 32, TRUE,   4, 4);
m_pImageList->Add(pApp->LoadIcon(IDI_ICONLIST1));
m_pImageList->Add(pApp->LoadIcon(IDI_ICONLIST2));
m_listctrl.SetImageList(m_pImageList, LVSIL_NORMAL);

However, if you don't plan to display icons in your list view or list control, you don't need image lists. See the sample application for an illustration of a list view with no icons.

See Also   Windows Common Controls and MFC Classes