Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to group the items in a ListView Control that displays in Tile View but when I do all the sub item text disappears (the same happens in when using Report View).

Here is the code I'm using, any ideas?

C++
//temporary use Report View 
//SetTileView();

//Create 2 Groups
{
LVGROUP lvg;
lvg.mask      = LVGF_HEADER | LVGF_ALIGN | LVGF_GROUPID | LVGF_STATE;
lvg.pszHeader = _T("Group 1");
lvg.iGroupId  = 0;
lvg.uAlign    = LVGA_FOOTER_LEFT;
lvg.state     = LVGS_NORMAL;
SendMessage(hList, LVM_INSERTGROUP, -1, (LPARAM)&lvg );
lvg.pszHeader = _T("Group 2");
lvg.iGroupId  = 1;
SendMessage(hList, LVM_INSERTGROUP, -1, (LPARAM)&lvg );
}

//Set number, style and size of Columns
{
LVCOLUMN lvc; 
int iCol; 

lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; 
lvc.fmt = LVCFMT_LEFT;
lvc.pszText =_T("Col");
lvc.cx = COLWIDTH;

// Add the columns. 
for (iCol = 0; iCol < VIEWCOLS; iCol++) 
 	{ 
 	lvc.iSubItem = iCol;
 	ListView_InsertColumn(hList, iCol, &lvc);
 	}	
}

//Set item amd sub item text and number of displayed items
{
UINT uCols[3] = {1,2,3};
LVTILEINFO lvti;
lvti.cbSize = sizeof(LVTILEINFO);
lvti.cColumns = VIEWCOLS;
lvti.puColumns = uCols;

LVITEM lvi;
memset(&lvi, 0, sizeof(LV_ITEM));
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID;
lvi.iGroupId = 0;

for(int n = 0; n < iNumLibs; n++)
 	{
 	lvi.iItem = n;
 	lvi.pszText = pszItemText[n];
 	lvi.iImage = n;
 	lvi.iSubItem = 0;
	ListView_InsertItem(hList, &lvi);
 	lvi.iSubItem = 1;
 	ListView_SetItem(hList, &lvi);
 	lvi.iSubItem = 2;
 	ListView_SetItem(hList, &lvi);
 	lvi.iSubItem = 3;
 	ListView_SetItem(hList, &lvi);
 	lvti.iItem = n;
 	ListView_SetTileInfo(hList, &lvti);
 	}
}

{
UINT uCols[3] = {1,2,3};
LVTILEINFO lvti;
lvti.cbSize = sizeof(LVTILEINFO);
lvti.cColumns = VIEWCOLS;
lvti.puColumns = uCols;

LVITEM lvi;
memset(&lvi, 0, sizeof(LV_ITEM));
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID;
lvi.iGroupId = 1;

for(int n = 0; n < 1; n++)
        {
        lvi.iItem = n;
        lvi.pszText = _T("Cert01");
        lvi.iImage = n;
        lvi.iSubItem = 0;
        ListView_InsertItem(hList, &lvi);
        }
}

ListView_EnableGroupView(hList, TRUE);
}
Posted
Comments
enhzflep 3-Jul-12 11:51am    
Haven't tried using LV groups before. I do note from your code that you don't set the cbSize member of your lvg struct. Looking at MSDN, we can see that the structure size changed at the transition to WIN32_WINNT == 0x600

Have had problems in the past with other structures didn't have cbSize set correctly.

EDIT: Just saw the note that says that you can't insert groups into an empty control. Another potential source of problems.
Member 4650365 3-Jul-12 12:51pm    
Oops missed that one, added it in - no change.

I have been using WIN32_WINNT == 0x0501 with manifest set for COMMCTRL V6.

I noticed the bit about empty groups as well, but you have to insert the groups before the items or nothing is displayed. Inserting the groups after the columns makes no difference either.
enhzflep 3-Jul-12 15:11pm    
Just found an example in which this works. It's a bit late in the day for my analytical skills, though surely you'll unravel it in no time.
http://www.winapizone.net/tutorials/winapi/listview/groups.php
-get the Example (plus a C::B project) if you just want an exe (unlikely)
-get the Demo (executable) if you want the project files too

(The files are attached to the wrong links)

I do note that it points out that there are 3 4 prerequisites to adding a group.
1)load comctrl.dll
2)style must be LVS_REPORT
3)have already added columns
4)have already enabled group-view

Haven't played with the code and tested above assertions. But the ode does work.

Enjoy!
Member 4650365 5-Jul-12 10:17am    
Thanks for the link, having checked the sample against my own code I have the answer:-

When setting the three sub-items in the "for(int n = 0; n < iNumLibs; n++)" loop I should have used:-

SendMessage(hList, LVM_SETITEMTEXT, n, (LPARAM)&lvi);

Not:-

ListView_SetItem(hList, &lvi);
Member 4650365 3-Jul-12 16:45pm    
Thanks for that enhzflep, I have the sample working, I just need to see where mine is different then all I need to do now is how to get is to keep working when I switch to tile view with "ListView_SetView(listView, LV_VIEW_TILE)" unless the tile view in Windows Explorer is extra code, not part of comctl32.dll.

1 solution

Thanks to enhzflep for the link, having checked the sample against my own code I have the answer:-

When setting the three sub-items in the "for(int n = 0; n < iNumLibs; n++)" loop I should have used:-

SendMessage(hList, LVM_SETITEMTEXT, n, (LPARAM)&lvi);

Not:-

ListView_SetItem(hList, &lvi);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900