Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding items to a ListView?

I'm having trouble adding items onto a ListView control. When I try to add items to my ListView, nothing happens. I was using this code before, and it didn't work.

I have 3 columns, with the SubItem values set to 1, 2, and 3.

   LVITEM item;
   item.mask = LVIF_TEXT;
   item.cchTextMax = 6;

   item.iSubItem = 1;
   item.pszText = TEXT("12345");
   item.iItem = 0;
   ListView_InsertItem(hListView, &item);

   item.iSubItem = 2; // zero based index of column
   item.pszText = TEXT("23456");
   ListView_InsertItem(hListView, &item);

   item.iSubItem = 3; // zero based index of column
   item.pszText = TEXT("34567");
   ListView_InsertItem(hListView, &item);
like image 346
Neal P Avatar asked Jul 10 '10 00:07

Neal P


1 Answers

From MSDN:

You cannot use ListView_InsertItem or LVM_INSERTITEM to insert subitems. The iSubItem member of the LVITEM structure must be zero. See LVM_SETITEM for information on setting subitems.

Try using ListView_SetItem() for the secondary columns (subitems 1 and 2) after adding the first column (subitem 0) with ListView_InsertItem().

like image 80
gwell Avatar answered Sep 22 '22 18:09

gwell