Could anyone provide an example of a listview control in tile view with subitems?

This might be a long shot but I though I would ask anyway. I have struggled with this in the past and never have been able to figure out how to do it, and MSDN isn't very clear about it.

Here are the steps I follow:
- Enable visual styles (required for tile view)
- Create the listview with CreateWindowEx
- Send LVM_SETVIEW with LV_VIEW_TILE
- Send LVM_SETTILEVIEWINFO with cLines of TILEVIEWINFO struct set to the # subitems I want
- Insert items like normal (Works fine)
- Set subitem text by sending LVM_SETITEM with iSubitem of LVITEM set (Does nothing!)

I saw this page here,
https://msdn.microsoft.com/en-us/library/windows/desktop/hh270408%28v=vs.85%29.aspx

and it mentions columns so I tried to insert columns before attempting to set subitem text but that doesn't work either (subitem text does not appear). I also tried setting cColumns member of the LVITEM structure when inserting items but then it fails to insert the items.

I don't know what else to try, so i'm asking if anyone has an example of this they could share I would be very grateful!
Last edited on
Why don't you show us your code?
Create the listview

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | LVS_SHAREIMAGELISTS;
DWORD exstyle = LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP;

hwnd = CreateWindowEx(
      0, 
      WC_LISTVIEW, 
      NULL, 
      style, 
      CW_USEDEFAULT, 
      CW_USEDEFAULT, 
      CW_USEDEFAULT, 
      CW_USEDEFAULT,
      parent, 
      NULL, 
      GetModuleHandle(NULL), 
      NULL);

SendMessage(hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)exstyle);


Set tile view

1
2
3
4
5
6
7
8
SendMessage(hwnd, LVM_SETVIEW, (WPARAM)LV_VIEW_TILE, 0);

LVTILEVIEWINFO tvi = {0};
tvi.cbSize = sizeof(LVTILEVIEWINFO);
tvi.dwMask = LVTVIM_COLUMNS;
tvi.cLines = 2; // 2 subitems

SendMessage(hwnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)&tvi);


Insert items

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Uncommenting code works fine but still no subitem text appears

// INT colfmt[2] = { LVCFMT_LEFT, LVCFMT_LEFT };
// UINT order[2];

LVITEM lvi = {0};
lvi.mask = LVIF_TEXT | LVIF_IMAGE | (group >= 0? LVIF_GROUPID: 0) | LVIF_PARAM; // LVIF_COLUMNS | LVIF_COLFMT
lvi.iItem = index;
lvi.iImage = image;
lvi.pszText = buffer;
lvi.lParam = param;
lvi.iGroupId = group;
// lvi.cColumns = 2;
// lvi.piColFmt = colfmt;
// lvi.puColumns = order;

INT ret = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&lvi);


Add columns

1
2
3
4
5
6
7
8
9
10
 // Commented code doesn't seem to have any effect

LVCOLUMN lvc = {0};
lvc.mask = LVCF_TEXT | (image >= 0? LVCF_IMAGE: 0) | LVCF_WIDTH; // LVCF_SUBITEM;
lvc.pszText = buffer;
lvc.cx = width;
lvc.iImage = image;
// lvc.iSubItem = subitem; 

INT ret = SendMessage(hwnd, LVM_INSERTCOLUMN, (WPARAM)index, (LPARAM)&lvc);


Set subitem text

1
2
3
4
5
6
7
LVITEM lvi = {0};
lvi.mask = LVIF_TEXT;
lvi.iItem = index;
lvi.iSubItem = subitem; // <-- nothing happens whether I add columns first or not
lvi.pszText = buffer;

SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&lvi);


In any other view this code works pretty much as is, I can add subitems and columns and everything works as it should.

I don't know if its the case here but I have encountered issues with some win32 structures where the cbSize member has to be set to some constant like LVTILEINFO_SIZE_V6(not a real constant) rather than the actual size of the structure. I couldn't find anything similar for the listview structs though.
Last edited on
Figured it out. I had to add this after setting the view to tile,

1
2
3
4
5
6
LVTILEVIEWINFO tvi = {0};
tvi.cbSize = sizeof(LVTILEVIEWINFO);
tvi.dwMask = LVTVIM_COLUMNS;
tvi.cLines = 3;

SendMessage(hwnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)&tvi);


and this when inserting items,

1
2
3
4
5
6
7
8
9
UINT cols[3] = {1, 2, 3}; // display columns 1, 2, and 3

LVTILEINFO lvt = {0};
lvt.cbSize = sizeof(LVTILEINFO);
lvt.cColumns = 3;
lvt.puColumns = cols;
lvt.iItem = ret;

SendMessage(hwnd), LVM_SETTILEINFO, 0, (LPARAM)&lvt);


Then all I had to do was insert columns for each item and subitem before attempting to set the subitem text.
Last edited on
Topic archived. No new replies allowed.