I'm currently trying to create a listview control in Win32 and add items and subitems. I was able to create the listview and add headers and items. The LVM_INSERTITEM message is working totally fine and it shows the different lines. But when I try to add Subitems with the LVM_SETITEM message, they don't show up. So I checked and the SendMessage function returns FALSE, so the function failed, but I have no idea why!
It is also weird that when I use the LVM_SETITEMTEXT message instead, it seems to work at first, but only for the first line, but not for the second or third. It always changes the text of the subitems from the first line.
This is the code I am using:
BOOL AddContactListview(HWND hWndListviewContact, CONTACT *AddContact, int cRecord)
{
LVITEM lvi;
char count[3];
//Insert Item
wsprintf(count, "%d", cRecord+1);
lvi.mask=LVIF_TEXT;
lvi.iItem=cRecord+1; //cRecord is raised 1 before every function call
lvi.iSubItem=0;
lvi.pszText=count;
SendMessage(hWndListviewContact, LVM_INSERTITEM, 0, (LPARAM) &lvi);
//Add Subitems from a structure
lvi.iItem=cRecord+1;
lvi.iSubItem=1;
lvi.pszText=AddContact->firstname;
SendMessage(hWndListviewContact, LVM_SETITEM, 0,(LPARAM) &lvi);
lvi.iSubItem=2;
lvi.pszText=AddContact->surname;
SendMessage(hWndListviewContact, LVM_SETITEM, 0,(LPARAM) &lvi);
lvi.iSubItem=3;
lvi.pszText=AddContact->street;
SendMessage(hWndListviewContact, LVM_SETITEM, 0,(LPARAM) &lvi);
lvi.iSubItem=4;
lvi.pszText=AddContact->streetnumber;
SendMessage(hWndListviewContact, LVM_SETITEM, 0,(LPARAM) &lvi);
lvi.iSubItem=5;
lvi.pszText=AddContact->city;
SendMessage(hWndListviewContact, LVM_SETITEM, 0,(LPARAM) &lvi);
lvi.iSubItem=6;
lvi.pszText=AddContact->phonenumber;
SendMessage(hWndListviewContact, LVM_SETITEM, 0,(LPARAM) &lvi);
return TRUE;
}