ROWLIST: Selecting Full Rows in List Views

Click to open or copy the ROWLIST project files.

The ROWLIST sample illustrates selecting full rows in a report mode of the CListView MFC common control class. The sample implements a reusable class, CListViewEx, that provides full row selection as an additional view mode of a list view control. CListViewEx uses the owner-draw mode to do all of the painting for the control. You can use the class in your own projects, either directly or as a base class. ROWLIST also demonstrates how to use state and overlay images with a list view control.

Running the Sample

When you run ROWLIST, it presents an SDI application whose view is a CListView-derived class. The view has items representing different colors, with additional data about them. The list view control comes up initially in the report mode, with full row selection enabled. The View menu and the toolbar allow you to select other view modes.

State images are initially set to an empty square on the left side of each item. If you click a state image, the item's image becomes an icon displayed on the caption bar (Windows 95 only). If state images are not displayed, you can double-click an item to change its state.

The CListViewEx Class

The class CListViewEx, derived from CListView, is a reusable class that implements the full row selection mode. The class provides complete support for the owner-draw mode of a list view control, and provides full row selection by implementing painting code for all images and labels. CListViewEx displays a control's images and labels exactly as in the report mode, with the addition of the full row selection. The class has only two additional member functions (as compared to CListView): SetFullRowSel and GetFullRowSel. These functions are used to set or query for the full row selection mode.

You can reuse the class in your own projects, either by deriving a class from it, or by using it directly. The simplest way to use the class is to use AppWizard to create an application that has a CListView-derived class, and then to change its base class to CListViewEx.

Using State and Overlay Images with a CListView

ROWLIST demonstrates use of state and overlay images. State images are initially set to an empty square on the left side of each item. If you click a state image, the item’s image becomes an icon displayed on the caption bar. In response, the item's state icon changes to a square with a check mark. CRowListView::OnLButtonDown contains the code that inserts the check mark if a state icon is selected, and that changes a state icon for an item.

If state images are not displayed, then the image currently in use will be marked with an overlay image on top of it (a gray square with a check mark). You can use a double-click to change the state of an item, which also toggles an overlay image on or off. The implementation code for the double-click is found in CRowListView::OnLButtonDblClk.