From: David Connet on
"David Ching" <dc(a)remove-this.dcsoft.com> wrote in
news:4OBOj.3245$h75.1600(a)newssvr27.news.prodigy.net:
> void CPageStock::OnGetdispinfoListPortfolio(NMHDR* pNMHDR, LRESULT*
> pResult) {
> // The data to display is stored in a CArray. Items in the array
> are
> accessed by
> // CAppData::GetStockRecord(int index).
> // The index of the item that Windows is asking for is
> pDispInfo->item.iItem. But the data stored
> // in this row of the list control can be different, if the list
> is
> sorted. The CArray index of the item
> // in the currently sorted order is stored in the item data.
> Therefore,
> the CArray index is gotten by
> // m_lcPortfolio.GetItemData(pDispInfo->item.iItem).
> LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
> CStockRecord *pStockRec = CAppData::GetStockRecord
> (m_lcPortfolio.GetItemData(pDispInfo->item.iItem));
>
> // Assuming the list control is in Report mode, must display
> different
> strings for the desired column.
> // The column being asked for is pDispInfo->item.iSubItem.
> switch (pDispInfo->item.iSubItem)
> {
> case 0:
> pDispInfo->item.pszText = (LPSTR) pStockRec->GetName();
> break;
>
> case 1:
> {
> pDispInfo->item.pszText = (LPSTR)pStockRec->GetCost();
> break;
> }
> }
> }

If you _know_ you only set a callback on text, I might see not testing
the mask, but there are many things you can get the callback for.

This should really test:
if (pDispInfo->item.mask & LVIF_TEXT)
{
...
}
if (pDispInfo->item.mask & LVIF_IMAGE)
{
...
}
Note, you may get more than one in a single call, so don't test if/else
if. In tree controls, I sometimes also set the number of children as a
callback, and then populate the child tree items when the node is
expanded.

Also, for others looking at this, if you assign directly to pszText (as
above), you must be assigning an address that will not change. If GetCost
() returns a temporary object, then do something like the following:
::lstrcpyn(pDispInfo->item.pszText, yourData, pDispInfo->
item.cchTextMax);

Dave Connet
From: David Ching on
"David Connet" <stuff(a)agilityrecordbook.com> wrote in message
news:sXIOj.2355$I55.1325(a)newssvr22.news.prodigy.net...
[a bunch of true stuff]

Thanks for filling in these details!

-- David


From: David Connet on
"David Ching" <dc(a)remove-this.dcsoft.com> wrote in news:btJOj.3269$h75.229
@newssvr27.news.prodigy.net:

> "David Connet" <stuff(a)agilityrecordbook.com> wrote in message
> news:sXIOj.2355$I55.1325(a)newssvr22.news.prodigy.net...
> [a bunch of true stuff]
>
> Thanks for filling in these details!
>
> -- David

No problem! I've played with list controls a bit - even as far as writing
an ownerdraw one. That was fun making sure state and normal icons displayed
properly... (That code belongs to my company, so I can't share it - sorry!)

I've always 'cheated' on the inserting a new item in a sorted list. I just
append it and then call SortItems (haven't run into any performance issues
yet, so why bother optimizing it).

Also, I really like storing data internally and using getdispinfo - then
when an item changes, all I have to do is invalidate the list (or if I know
the specific item, I just invalidate that) and the new data displays! No
need to find the item and do a SetItemText. Sometimes laziness makes life
sooo much easier!

Dave Connet