Click to See Complete Forum and Search --> : Id for a row in CListCtrl


October 13th, 1999, 06:50 PM
I have a linked list of objects that are displayed on a list control. When I double click on the row I want to be able to find the object
in my linked list from the info in the row, possibly some kind of row id that I can save in my object. Is there a standard way to do
this? I was thinking it had something to do with the lParam of the LV_ITEM structure, but I'm not sure how to use this.

Thanks in advance.

Sam Hobbs
October 14th, 1999, 12:47 AM
See CListCtrl::SetItemData and CListCtrl::GetItemData. I think the documentation has all the answers that you are seeking.

October 14th, 1999, 09:29 AM
You can save linked list pointer in your list control using SetItemData() and retrive pointer back by GetItemData().you need to cast pointer to DWORD and vise versa.

like
m_ptrlistObject is a pointer to a object in list
pListCtrl->SetItemData(nIndex,(DWORD)m_ptrlistObject);

retrive
int nItem = pListCtrl->GetNextSelectedItem(pos);
m_ptrlistObject=(yourobject*)pListCtrl->GetItemData(nItem);

hope this works