Problems with GetItemData in CList

orik1

New member
Problems with GetItemData in CList

Hi. I'm having problems with CListCtrl GetItemData - it always returns 0. We're talking about a modal dialog - in which values to the items are set using SetItemData in the OnInitDialog method. Checking for the values anywhere (after SetData of course) in OnInitDialog returns the correct values. When trying to GetItemData in OnOK - i always get 0. Item index is correct, since if i try to GetItemText - i get the correct text, only the data is 0. here is some code : the SetItemData in InitDialog: for(int i = 0; i < arrEntities.GetCount(); ++i)// Iterate objects { CMyObject element = arrEntities.ElementAt(i); // extract object CString sDisplayName = element.Title(); m_listSelection.InsertItem(i, sDisplayName); // Insert item m_listSelection.SetItemData(i, (DWORD_PTR) element); // & data } and the GetItemData in OnOK: UINT i, uSelections = m_listSelection.GetSelectedCount(); int nItem = -1; if (uSelections > 0) { for (i=0;i < uSelections;i++) { nItem = m_listSelection.GetNextItem(nItem, LVNI_SELECTED); ASSERT(nItem != -1); CString s = m_listSelection.GetItemText(nItem, 0); // Text is ok DWORD_PTR d = m_listSelection.GetItemData(nItem);// data is 0 } } CMyObject has a cast operator to DWORD_PTR, but still ONLY in OnOK GetItemData returns 0. Any ideas ?​
 
למעלה