Group Header Color in ListView control
When I try to use LVM_SETGROUPMETRICS / ListView_SetGroupMetrics / SetGroupMetrics() in Vista, there is no way to set the group header color, it is ignored.
The following code applied to a ListView / ListCtrl will make the group header show up green in XP , in Vista the group header doesn't change color, it always stays blue.
Is there any way to change a ListView controls group header color in Vista ?
Sample Code :
// in OnInitDialog(), m_list is a CListCtrl on a CDialog : ListView_SetExtendedListViewStyleEx( m_list.m_hWnd, 0, LVS_EX_DOUBLEBUFFER ); m_list.EnableGroupView( true ); AddGroup( 0, _T("Group 0") ); m_list.InsertColumn( 0, _T("Col"), LVCFMT_LEFT, 150 ); for ( int i = 0; i< 10; i++ ) m_list.InsertItem( i, str ); return TRUE; // return TRUE unless you set the focus to a control void CListCtrlTestDlg::SetGroupColor() void CListCtrlTestDlg::AddGroup( int iIndex, CString strHeader ) m_list.InsertGroup( iIndex, &group ); void CListCtrlTestDlg::MoveItemToGroup( int iItemIndex, int iGroupID ) m_list.SetItem( &lvItem ); }
SetGroupColor();
AddGroup( 1, _T("Group 1") );
AddGroup( 2, _T("Group 2") );
{
CString str;
str.Format( _T("Item %d"), i );
MoveItemToGroup(i, i%3);
}
}
{
LVGROUPMETRICS metrics;
ZeroMemory( &metrics, sizeof(LVGROUPMETRICS) );
metrics.cbSize = sizeof( LVGROUPMETRICS );
metrics.mask = LVGMF_TEXTCOLOR;
metrics.crHeader = RGB(0,255,0); // Green
m_list.SetGroupMetrics( &metrics );
}
{
LVGROUP group;
ZeroMemory( &group, sizeof( LVGROUP ) );
group.cbSize = sizeof( LVGROUP );
group.iGroupId = iIndex;
group.mask = LVGF_HEADER | LVGF_GROUPID | LVGF_STATE;
group.state = LVGS_NORMAL;
group.pszHeader = strHeader.GetBuffer();
group.cchHeader = strHeader.GetLength();
strHeader.ReleaseBuffer();
}
{
LVITEMW lvItem;
lvItem.mask = LVIF_GROUPID;
lvItem.iItem = iItemIndex;
lvItem.iSubItem = 0;
lvItem.iGroupId = iGroupID;

