HOWTO: Highlight Entire Row of Multi-Column Report-View CListCtrlR

ID: Q230049


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0, 6.0


SUMMARY

The ListView common control in a multi-column report view mode highlights only the first column when a row is selected. This behavior is by design.


MORE INFORMATION

To enable complete row selection, you need to send the LVM_SETEXTENDEDLISTVIEWSTYLE message to the control and specify the LVS_EX_FULLROWSELECT extended style.

Create a CListCtrl derived class, CMyListCtrl. Using ClassWizard, create a handler for the WM_CREATE message for CMyListCtrl. Then, in the definition of the handler, copy the code shown below. Now use CMyListCtrl in place of CListCtrl in your project.


int CMyListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
   if (CListCtrl::OnCreate(lpCreateStruct) == -1)
      return -1;

   DWORD dwStyle = ::SendMessage(m_hWnd,LVM_GETEXTENDEDLISTVIEWSTYLE,0,0);
   dwStyle |= LVS_EX_FULLROWSELECT;
   ::SendMessage(m_hWnd,LVM_SETEXTENDEDLISTVIEWSTYLE,0,dwStyle);

// or you could also use

// ListView_SetExtendedListViewStyle(
//            m_hWnd, 
//            ListView_GetExtendedListViewStyle(m_hWnd)
//            | LVS_EX_FULLROWSELECT);


// or you could also use

// SetExtendedStyle(GetExtendedStyle() | LVS_EX_FULLROWSELECT);

   return 0;
}
 


REFERENCES

  1. Q147842 HOWTO: Detect a Mouse Click on Any Column of List View Control


  2. LISTHDR: Demonstrates the List View and Header Common Controls


  3. Q181440 Add Full Row Select Functionality to a ListView Control

    NOTE: Article Q181440 shows how this could be achived in Visual Basic.


  4. Q131788 SAMPLE: OdListVw.exe Highlighs Entire Row in a ListView Control[win32 sdk]


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Vidyanand, Microsoft Corporation

Additional query words: Select Highlight Report CListCtrl ListView

Keywords : kbfile kbCmnCtrls kbCtrl kbListView kbMFC kbVC600 kbGrpMFCATL
Version : winnt:4.2,5.0,6.0
Platform : winnt
Issue type : kbhowto


Last Reviewed: August 23, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.