Click to See Complete Forum and Search --> : Listview groups not working


kkez
November 16th, 2005, 10:51 AM
I've attached an example of a dialog with a listview where i add a column, some items and two groups: the problem is that the group aren't visible even if ListView_InsertGroup doesn't fail and there are items in the group. :confused:

PS i didn't include a project cause i'm working with codeblocks & mingw :)

NoHero
November 16th, 2005, 11:30 AM
Remove the detail view style and the insertion of the columns. You also have to set the LVIF_GROUPID bit in the LVITEM's mask, otherwise all items are added to the first group only.

HWND listView = GetDlgItem(hwnd, IDC_LISTVIEW);


//Groups
LVGROUP lg;
lg.cbSize = sizeof(LVGROUP);
lg.mask = LVGF_HEADER | LVGF_GROUPID;

lg.pszHeader = L"Group1";
lg.iGroupId = 0;
ListView_InsertGroup(listView, -1, &lg);

lg.pszHeader = L"Group2";
lg.iGroupId = 1;

ListView_InsertGroup(listView, -1, &lg);


//items
LVITEM li;
li.mask = LVIF_TEXT | LVIF_GROUPID;
li.iSubItem = 0;

li.pszText = "Item1 in group1";
li.iItem = 0;
li.iGroupId = 0;
ListView_InsertItem(listView, &li);

li.pszText = "Item1 in group2";
li.iItem = 1;
li.iGroupId = 1;
ListView_InsertItem(listView, &li);

if ( !ListView_EnableGroupView(listView, TRUE) )
{
MessageBox(NULL, "Could not set group view!", "Error", MB_ICONEXCLAMATION);
}

kkez
November 16th, 2005, 12:18 PM
Well, it's working now, but:


now all items get inserted in the first group, even if i use the LVIF_GROUPID flag and set different IDs
the second group isn't displayed even if there are some items
if i change the id of all the groups to something different from 0 and 1, again nothing is displayed :confused:
the image attached (the normal "my computer" window) did lead me to think it was possible to use group AND report, but it seems that windows is doing the drawing (that listview is subclassed), and i could try to do the same, but i don't see the way to get rid of the (sort of) icon view mode

NoHero
November 16th, 2005, 12:29 PM
Well, it's working now, but:

now all items get inserted in the first group, even if i use the LVIF_GROUPID flag and set different IDs
the second group isn't displayed even if there are some items


This worked for me... though... I inserted two groups with id 0 and 1. (As you did), and then added the items with mask LVIF_TEXT and LVIF_GROUPID, setting iGroup to 0 and 1. And it worked for me... :confused:. Maybe you overlooked something or your compiler/framework (mingw) does not support it.

Well, it's working now, but:

if i change the id of all the groups to something different from 0 and 1, again nothing is displayed :confused:


Yes... I guess the group id should start at zero.

Well, it's working now, but:

the image attached (the normal "my computer" window) did lead me to think it was possible to use group AND report, but it seems that windows is doing the drawing (that listview is subclassed), and i could try to do the same, but i don't see the way to get rid of the (sort of) icon view mode


Hmm... Yes I know, but I guess the windows explorer manually added a column header. Or maybe there is a trick on how to use groups in detail view. But frankly I am not aware of one... :(

Darrell_L
November 16th, 2005, 04:56 PM
I have a working app that displays columns while in group view, so I know it's doable.

I just made sure to insert the columns and groups and enable the group view before any items were added, and to also include the 2 column-related fields, cColumns and and puColumns, in the LVITEM used to insert items.

Other than that, no tricks and no subclassing are required.

kkez
November 17th, 2005, 08:45 AM
I have a working app that displays columns while in group view, so I know it's doable.

I just made sure to insert the columns and groups and enable the group view before any items were added, and to also include the 2 column-related fields, cColumns and and puColumns, in the LVITEM used to insert items.

Other than that, no tricks and no subclassing are required.

Yes! Now it's working! Can't believe the documentation is so poor.
Actually, it seems to me that i need only to set cColumn member, and this member has to be the same number of the group (of course i set at the same time the LVIF_COLUMNS flag). Everything is working, and i don't need to set the puColumns member. Strange but it works :thumb:

This code is the one i'm using:
HWND listView = GetDlgItem(hwnd, IDC_LISTVIEW);
ListView_EnableGroupView(listView, TRUE);

//Columns
LVCOLUMN lc;
lc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;

lc.iSubItem = 0;
lc.cx = 100;
lc.pszText = "Column1";
ListView_InsertColumn(listView, 0, &lc);

lc.iSubItem = 1;
lc.cx = 120;
lc.pszText = "Column2";
ListView_InsertColumn(listView, 1, &lc);

lc.iSubItem = 2;
lc.cx = 120;
lc.pszText = "Column3";
ListView_InsertColumn(listView, 2, &lc);

//Groups
LVGROUP lg;
lg.cbSize = sizeof(LVGROUP);
lg.mask = LVGF_HEADER | LVGF_GROUPID;

lg.pszHeader = L"Group1";
lg.iGroupId = 101;
ListView_InsertGroup(listView, -1, &lg);

lg.pszHeader = L"Group2";
lg.iGroupId = 102;
ListView_InsertGroup(listView, -1, &lg);


//items
LVITEM li;
li.mask = LVIF_TEXT | LVIF_GROUPID | LVIF_COLUMNS;

li.pszText = "Item1 Group1";
li.iItem = 0;
li.iSubItem = 0;
li.iGroupId = 101;
li.cColumns = 101;
ListView_InsertItem(listView, &li);
ListView_SetItemText(listView, 0, 1, "Subitem1 Group1");

li.pszText = "Item2 Group1";
li.iItem = 1;
li.iSubItem = 0;
li.iGroupId = 101;
li.cColumns = 101;
ListView_InsertItem(listView, &li);
ListView_SetItemText(listView, 1, 1, "Subitem2 Group1");
ListView_SetItemText(listView, 1, 2, "Subitem3 Group1");

li.pszText = "Item3 Group1";
li.iItem = 2;
li.iSubItem = 0;
li.iGroupId = 101;
li.cColumns = 101;
ListView_InsertItem(listView, &li);
ListView_SetItemText(listView, 2, 1, "Subitem3 Group1");

li.pszText = "Item1 Group2";
li.iItem = 0;
li.iSubItem = 0;
li.iGroupId = 102;
li.cColumns = 102;
ListView_InsertItem(listView, &li);
ListView_SetItemText(listView, 0, 1, "Subitem2 Group2");


And a screenshot:

kkez
November 17th, 2005, 08:56 AM
Another little thing, what theme are you using (if that's windows)?

Darrell_L
November 17th, 2005, 05:02 PM
Another little thing, what theme are you using (if that's windows)?

Glad things are working for you now.

The theme is called OpusOS, http://www.deviantart.com/deviation/4591314/.

kkez
November 18th, 2005, 06:21 AM
The theme is called OpusOS, http://www.deviantart.com/deviation/4591314/.

Thank you again :)