CMyListCtrl
处于虚拟数据模式且所有者绘制。当控件想要数据时,会发送LVN_GETDISPINFO
通知。
下面的代码工作正常,但它会多次显示每一行。
文档说如果我设置了项目掩码的LVIF_DI_SETITEM
标志,它就不会这样做。文档还说pItem->iGroupId
必须在我InsertItem
之前设置,但是控件仍然为每个插入的行显示多行。
void CMyListCtrl::OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
//Create a pointer to the item
LV_ITEM* pItem= &(pDispInfo)->item;
CString text, strippedText;
//Does the control need text information?
if( pItem->mask & LVIF_TEXT )
{
if(pItem->iSubItem == 0) // only first column used
{
text.Format( L"%s", cacheNotifyVect[ cacheNdx ] );
//Copy the text to the LV_ITEM structure
lstrcpyn(pItem->pszText, text, pItem->cchTextMax);
pItem->mask |= LVIF_DI_SETITEM; // documentation says to set this so the list-view control will store the requested data and will not ask for it again. The application must set the iGroupid member of the LVITEM structure.
}
}
*pResult = 0;
}
void CMyListCtrl::AddNotifyString(const CString & outListStr)
{
cacheNotifyVect[ cacheNdx % CACHE_CAPACITY] = outListStr; // RT:130908: make cache round robin for notify
LVITEM item;
item.mask = LVIF_TEXT;
item.iItem = cacheNdx++;
item.iSubItem = 0;
item.iGroupId = I_GROUPIDNONE; // so control will store data internally
item.pszText = (LPTSTR)(LPCTSTR)( outListStr );
outputWnd->outputNotify.InsertItem( &item );
答案 0 :(得分:0)
您已将item.mask设置为LVIF_TEXT,因此仅会观察iItem成员并忽略iGroupId成员。将item.mask设置为LVIF_TEXT | LVIF_GROUPID。