SAMPLE: OdListVw.exe Highlighs Entire Row in a ListView Control

ID: Q131788

The information in this article applies to:

SUMMARY

One of the limitations of the ListView common control is that when the control is in report view, the control only highlights the first column when a row is selected. To work around this limitation, you can create the ListView as an owner draw control (using the LVS_OWNERDRAWFIXED style) and perform all the painting yourself.

The ODLISTVW sample demonstrates how to create an owner draw ListView control that highlights an entire row.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ ODLISTVW.EXE (size: 428262 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from
               Online Services

One of the supported styles for the ListView control is LVS_OWNERDRAWFIXED, which allows the program to perform all the drawing of items in the ListView control. Whenever the ListView control needs to have a portion of the control repainted, it calculates which items are in that area and sends a WM_DRAWITEM message to its parent for each item. If any part of an item needs to be redrawn, the ListView sends the WM_DRAWITEM with the update rectangle set to the entire item.

The ListView control handles owner drawn items differently from other owner drawn controls. Previous owner drawn controls use the DRAWITEMSTRUCT's itemAction field to let the parent know if it needs to draw the item, change the selected state, or change the focus state. The ListView control always sends the WM_DRAWITEM message with the itemAction set to ODA_DRAWENTIRE. The parent needs to check the itemState to see if the focus or selection needs to be updated.

The LVS_OWNERDRAWFIXED style is only compatible with the LVS_REPORT style. You cannot have an owner drawn ListView with the LVS_ICON, LVS_SMALLICON or LVS_LIST style.

Additional query words: CListCtrl CListView list control kbui kbfile Keywords : kbfile kbsample kbCtrl kbSDKWin32 kbGrpUser

Last Reviewed: January 2, 1999