IonicWind Software

Aurora Compiler => Tips and Tricks => Topic started by: sapero on August 29, 2008, 07:35:44 PM

Title: Grouping items in listview
Post by: sapero on August 29, 2008, 07:35:44 PM
This example shows how to create a listview which looks like My Computer folder in Windows XP.
Requirements: Windows XP, visual styles manifest.
CApp::OnInitDialog(),int
{
HWND hwndList = GetDlgItem(m_hwnd, 1000);

LVGROUP lvgr;
LVITEM  lvi;

// A group cannot be inserted into an empty ListView control
lvi.iItem    = 0;
lvi.iSubItem = 0;
lvi.mask     = LVIF_TEXT;
lvi.pszText  = NULL;
SendMessage(hwndList, LVM_INSERTITEM, 0, &lvi);
// you can later call LVM_MOVEITEMTOGROUP(item, group) to move this item to a group

SendMessage(hwndList, LVM_ENABLEGROUPVIEW, true, 0);
lvi.mask     = LVIF_TEXT | LVIF_GROUPID;

lvgr.cbSize  = sizeof(lvgr);
lvgr.mask    = LVGF_ALIGN | LVGF_HEADER | LVGF_GROUPID;
lvgr.uAlign  = LVGA_HEADER_LEFT;

// create first group
lvgr.iGroupId  = 0;
lvgr.pszHeader = L"my header 1";
SendMessage(hwndList, LVM_INSERTGROUP, -1, &lvgr);

// create second group
lvgr.iGroupId  = 1;
lvgr.pszHeader = L"my header 2";
SendMessage(hwndList, LVM_INSERTGROUP, -1, &lvgr);

// insert items to first group
lvi.iGroupId = 0;
lvi.pszText  = "item in first group";
SendMessage(hwndList, LVM_INSERTITEM, 0, &lvi);
lvi.pszText  = "one more";
SendMessage(hwndList, LVM_INSERTITEM, 0, &lvi);

// insert items to second group
lvi.iGroupId = 1;
lvi.pszText  = "item in second group";
SendMessage(hwndList, LVM_INSERTITEM, 0, &lvi);
lvi.pszText  = "one more";
SendMessage(hwndList, LVM_INSERTITEM, 0, &lvi);
}


Attached complete project for experimenting ;)
Note: if you modify strings before the first unicode string, the gropus may fail to create, because our current parser does not guarantee WORD align for unicode strings. If you stick with this problem, just add or remove one character (like space) to one of strings before unicode stuff.
Title: Re: Grouping items in listview
Post by: pistol350 on September 01, 2008, 02:28:58 PM
That's quite interesting.
Thank you for sharing it.  8)