How to store data with items in a virtual listview?
How to store data with items in a virtual listview while processing LVN_GETDISPINFO message? foolowing code doesn't work.
void CWAVListView::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
LV_ITEM* pItem = &(pDispInfo)->item;
DWORD dwIdx = pItem->iItem;
LCID nLocaleID = GetUserDefaultLCID();
if (pItem->mask & LVIF_TEXT)
{
switch(pItem->iSubItem)
{
case 0: // fill the main text
lstrcpy(pItem->pszText, pWaItem->m_csName);
break;
case 1: // item type
lstrcpy(pItem->pszText, csItemType);
break;
case 2: // timestamp
COleDateTime ModifiedDate( pWaItem->m_nYear,
pWaItem->m_nMonth,
pWaItem->m_nDay,
pWaItem->m_nHour,
pWaItem->m_nMinute,
pWaItem->m_nSecond );
lstrcpy(pItem->pszText, ModifiedDate.Format(0, nLocaleID));
break;
//default:
//break;
}//switch()
}
if(pItem->mask & LVIF_IMAGE)
{
pItem->iImage = icon;
}
//***NOTE: following code doesn't work, why? mask is never LVIF_PARAM !!
if(pItem->mask & LVIF_PARAM)
{
pItem->lParam = pWaItem->m_nItemID;
}
*pResult = 0;
}
Re: How to store data with items in a virtual listview?
The reason OnGetdispinfo() does not have the mask with LVIF_PARAM set it that it is never needed to display. That information is set when you insert the the items into the CLsitCtrl regardless if you are useing OnGetdispinfo. This is useful if you alway sorting.
m_MyListCtrl.DeleteAllItems();
m_MyListCtrl.SetItemCount(total);
memset(&lvi, 0, sizeof(lvi));
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.pszText = LPSTR_TEXTCALLBACK;
lvi.iSubItem = 0;
for(i=0; i<total; i++)
{
lvi.iItem = i;
lvi.lParam = i;
m_MyListCtrl.InsertItem(&lvi);
}