Microsoft KB Archive/230049

= How to highlight a whole row in the ListView common control in a multicolumn report view mode =

Article ID: 230049

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q230049

<div class="notice_section">

Note Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

<div class="summary_section">

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

<div class="moreinformation_section">

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; }

The code above works only for dynamically created list controls. For controls created on the dialog resource, similar code should be placed in the OnInitDialog function.

<div class="references_section">