Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

ListView question.....

LVITEM item;
ZeroMemory(&item, sizeof(item));
item.mask = LVIF_TEXT;
item.iItem = ListView_GetItemCount(GetDlgItem(hWnd, IDC_LIST1));
item.pszText = data;
ListView_InsertItem(GetDlgItem(hWnd, IDC_LIST1), &item);

Ok, that is what I have.  And yes, the hWnd is entered right, I know this.. because I tested it with a MessageBox.  now...  data, DOES have text in it.  The following line works:


It shows up on the dialog box, with the correct data that I want to place in the ListView.  The list view IS called IDC_LIST1,  but this doesn't work!!!  ListView_InsertItem does not work... and I do not know why.  Can anyone assist me please!  Thank you.
1 Solution
ListView has some fitcher:
your data must be allocated and used only for
for this item(not used for other).
Next is my code: exist really only one(but very
important) difference:

int TMyListView::AddItem(char *szText, int iItem)
  LV_ITEM lvi;
    // Initialize LV_ITEM members that are common to all items.
  lvi.state = 0;
  lvi.stateMask = 0;
  lvi.pszText = LPSTR_TEXTCALLBACK;   // app. maintains text
  lvi.iImage = 0;                     // image list index

        // item label and the text of each subitem.
   char *pItem = strdup(szText); //this is difference!!!!

        // Initialize item-specific LV_ITEM members.
   lvi.iItem = iItem;
   lvi.iSubItem = 0;
   lvi.lParam = (LPARAM) pItem;    // item data

        // Add the item.
  return ::SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) (const LV_ITEM FAR *)&lvi);

police1Author Commented:
Cool, thanks a lot!  :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now