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);
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With