EDN Admin
Well-known member
I have a ListView control in my simple which have one group, I want to set the items group id dynamic, but I never receive LVIF_GROUPID notify in LVN_GETDISPINFO. Its work properly in Win7, So how to fix this issue? below is the code
snap
<span style="white-spacere m_ListCtrl.SetImageList(&m_ImgList, LVSIL_SMALL);
<span style="white-spacere VERIFY(m_ListCtrl.EnableGroupView(TRUE) == 1);
<span style="white-spacere CString wstrGroupName(_T("Running"));
<span style="white-spacere LVGROUP lvg;
<span style="white-spacere ZeroMemory(&lvg, sizeof(lvg));
<span style="white-spacere lvg.cbSize = sizeof(lvg);
<span style="white-spacere lvg.mask = LVGF_HEADER | LVGF_GROUPID | LVGF_ALIGN;
<span style="white-spacere lvg.pszHeader = wstrGroupName.GetBuffer();
<span style="white-spacere lvg.cchHeader = (int)wcslen(lvg.pszHeader);
<span style="white-spacere lvg.iGroupId = 1;
<span style="white-spacere lvg.uAlign = LVGA_HEADER_CENTER;
<span style="white-spacere VERIFY(m_ListCtrl.InsertGroup(-1, &lvg) > -1);
<span style="white-spacere
<span style="white-spacere // Insert column(s) (only needed for report view)
<span style="white-spacere m_ListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT, 26);
<span style="white-spacere m_ListCtrl.InsertColumn(1, _T("Item Context"), LVCFMT_LEFT, 160);
<span style="white-spacere // Insert items
<span style="white-spacere for (int i=1; i<=20; i++)
<span style="white-spacere {
<span style="white-spacere // Set item group ID
<span style="white-spacere LVITEM lvi;
<span style="white-spacere ZeroMemory(&lvi, sizeof(lvi));
<span style="white-spacere
<span style="white-spacere lvi.mask = LVIF_GROUPID | LVIF_IMAGE ;
<span style="white-spacere lvi.iImage = i % 2 == 0 ? I_IMAGENONE : 0;
<span style="white-spacere lvi.iGroupId = I_GROUPIDCALLBACK;
<span style="white-spacere lvi.iItem = i ;
<span style="white-spacere int iItem = m_ListCtrl.InsertItem(&lvi);
<span style="white-spacere
<span style="white-spacere ZeroMemory(&lvi, sizeof(lvi));
<span style="white-spacere CString strMsg;
<span style="white-spacere if (i % 2 == 0)
<span style="white-spacere {
<span style="white-spacere strMsg.Format(_T("My Sub-Item(%d)"), i / 2);
<span style="white-spacere lvi.mask = LVIF_IMAGE | LVIF_TEXT;
<span style="white-spacere }
<span style="white-spacere else
<span style="white-spacere {
<span style="white-spacere lvi.mask = LVIF_TEXT ;
<span style="white-spacere strMsg.Format(_T("My Item(%d)"), i / 2 + 1);
<span style="white-spacere }
<span style="white-spacere lvi.iImage = 1;
<span style="white-spacere lvi.pszText = strMsg.GetBuffer();
<span style="white-spacere lvi.cchTextMax = strMsg.GetLength();
<span style="white-spacere lvi.iItem = iItem;
<span style="white-spacere lvi.iSubItem = 1;
<span style="white-spacere ASSERT(m_ListCtrl.SetItem(&lvi));
<span style="white-spacere }
void CLstDlg::OnLvnGetdispinfoJobs(NMHDR *pNMHDR, LRESULT *pResult)
{
<span style="white-spacere NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
<span style="white-spacere if (pDispInfo->item.mask & LVIF_GROUPID)
<span style="white-spacere {
<span style="white-spacere //Never run here? strange, work OK on Win7
<span style="white-spacere pDispInfo->item.iGroupId = 1;
<span style="white-spacere }
<span style="white-spacere *pResult = 0;
}
Thanks
View the full article
snap
<span style="white-spacere m_ListCtrl.SetImageList(&m_ImgList, LVSIL_SMALL);
<span style="white-spacere VERIFY(m_ListCtrl.EnableGroupView(TRUE) == 1);
<span style="white-spacere CString wstrGroupName(_T("Running"));
<span style="white-spacere LVGROUP lvg;
<span style="white-spacere ZeroMemory(&lvg, sizeof(lvg));
<span style="white-spacere lvg.cbSize = sizeof(lvg);
<span style="white-spacere lvg.mask = LVGF_HEADER | LVGF_GROUPID | LVGF_ALIGN;
<span style="white-spacere lvg.pszHeader = wstrGroupName.GetBuffer();
<span style="white-spacere lvg.cchHeader = (int)wcslen(lvg.pszHeader);
<span style="white-spacere lvg.iGroupId = 1;
<span style="white-spacere lvg.uAlign = LVGA_HEADER_CENTER;
<span style="white-spacere VERIFY(m_ListCtrl.InsertGroup(-1, &lvg) > -1);
<span style="white-spacere
<span style="white-spacere // Insert column(s) (only needed for report view)
<span style="white-spacere m_ListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT, 26);
<span style="white-spacere m_ListCtrl.InsertColumn(1, _T("Item Context"), LVCFMT_LEFT, 160);
<span style="white-spacere // Insert items
<span style="white-spacere for (int i=1; i<=20; i++)
<span style="white-spacere {
<span style="white-spacere // Set item group ID
<span style="white-spacere LVITEM lvi;
<span style="white-spacere ZeroMemory(&lvi, sizeof(lvi));
<span style="white-spacere
<span style="white-spacere lvi.mask = LVIF_GROUPID | LVIF_IMAGE ;
<span style="white-spacere lvi.iImage = i % 2 == 0 ? I_IMAGENONE : 0;
<span style="white-spacere lvi.iGroupId = I_GROUPIDCALLBACK;
<span style="white-spacere lvi.iItem = i ;
<span style="white-spacere int iItem = m_ListCtrl.InsertItem(&lvi);
<span style="white-spacere
<span style="white-spacere ZeroMemory(&lvi, sizeof(lvi));
<span style="white-spacere CString strMsg;
<span style="white-spacere if (i % 2 == 0)
<span style="white-spacere {
<span style="white-spacere strMsg.Format(_T("My Sub-Item(%d)"), i / 2);
<span style="white-spacere lvi.mask = LVIF_IMAGE | LVIF_TEXT;
<span style="white-spacere }
<span style="white-spacere else
<span style="white-spacere {
<span style="white-spacere lvi.mask = LVIF_TEXT ;
<span style="white-spacere strMsg.Format(_T("My Item(%d)"), i / 2 + 1);
<span style="white-spacere }
<span style="white-spacere lvi.iImage = 1;
<span style="white-spacere lvi.pszText = strMsg.GetBuffer();
<span style="white-spacere lvi.cchTextMax = strMsg.GetLength();
<span style="white-spacere lvi.iItem = iItem;
<span style="white-spacere lvi.iSubItem = 1;
<span style="white-spacere ASSERT(m_ListCtrl.SetItem(&lvi));
<span style="white-spacere }
void CLstDlg::OnLvnGetdispinfoJobs(NMHDR *pNMHDR, LRESULT *pResult)
{
<span style="white-spacere NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
<span style="white-spacere if (pDispInfo->item.mask & LVIF_GROUPID)
<span style="white-spacere {
<span style="white-spacere //Never run here? strange, work OK on Win7
<span style="white-spacere pDispInfo->item.iGroupId = 1;
<span style="white-spacere }
<span style="white-spacere *pResult = 0;
}
Thanks
View the full article