我试图通过以下代码使用CListCtrl进行分组:
LVGROUP lg = { 0 };
lg.cbSize = sizeof(lg);
lg.state = LVGS_NORMAL | LVGS_COLLAPSIBLE;
lg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE | LVGF_ALIGN | LVGF_STATE | LVGF_DESCRIPTIONTOP | LVGF_DESCRIPTIONBOTTOM | LVGF_FOOTER | LVGF_TASK | LVGF_SUBTITLE | LVGF_SUBSET;
lg.uAlign = LVGA_HEADER_LEFT | LVGA_FOOTER_RIGHT;
LVITEM item = { 0 };
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID;
item.iSubItem = 0;
item.state = 0;
item.stateMask = LVIS_SELECTED;
CString s;
lg.iGroupId = 0;
s = L"Office";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 0;
s = "Pen";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Pencil";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
lg.iGroupId = 1;
s = L"Workshop";
lg.pszHeader = s.GetBuffer();
lg.cchHeader = s.GetLength();
pListCtrl->InsertGroup(lg.iGroupId, &lg);
item.iGroupId = 1;
s = "Hammer";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Drill";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
s = "Saw";
item.pszText = s.GetBuffer();
item.cchTextMax = s.GetLength();
pListCtrl->InsertItem(&item);
但是所有内容都显示为未分组
如何让小组按预期工作?