Вопрос

I have a CListCtrl and I want to store a UINT32 value, but it always returns 0 when I read with GetItemData

I have this code:

UINT CMyDialog::MyThread(LPVOID pArg)
  for (int nItem=0; nItem<50; nItem++)
  {
    UINT32 nNum=100;
    pDlg->m_listCtrl.InsertItem(0, _T("text")); // this works
    pDlg->m_listCtrl.SetItemData(nItem, nNum); // this not
   }
 }

/// this is called from a Dialog member function when a button is pressed

void CMyDialog::OnBtnClicked()
{
  UINT32 nRead=0;
  nRead=m_listCtrl.GetItemData(5);

  // nRead always returns 0
 }

Even if I use int or DWORD instead of UINT I get the same result.

Это было полезно?

Решение

Please be more careful posting your code. It's so simple to use cut and paste that there is no excuse for making error after error. It's very hard to help you and hardly worth it since you don't accept many answers.

At any rate, I do see a problem with your loop. You should be using the return value from InsertItem() like this:

UINT CMyDialog::MyThread(LPVOID pArg)
{
    for (int nItem=0; nItem<50; nItem++)
    {
        UINT32 nNum=100;
        int nIndex = pDlg->m_listCtrl.InsertItem(0, _T("text"));
        pDlg->m_listCtrl.SetItemData(nIndex, nNum);
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top