ROWLIST Sample: Demonstrates Selecting Full Rows in List Views
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 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.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
Building and Running the Sample
To build and run the ROWLIST sample
Open the solution rowlist.sln.
On the Build menu, click Build.
On the Debug menu, click Start Without Debugging.
When you run ROWLIST, it presents a single-document interface (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. If state images are not displayed, you can double-click an item to change its state.
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 the application wizard 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.
Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.