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.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

To build and run the ROWLIST sample

  1. Open the solution rowlist.sln.

  2. On the Build menu, click Build.

  3. 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.

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 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.

Note

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.

See Also

Other Resources

MFC Samples