Problem mit ListView-Items...
-
Hi,
ich hab ein kleines Problem mit listview:
[cpp]struct ITEMS { char iItem[20]; }; ITEMS items[] = { {"Text1"}, {"Text2"}, {"Text3"} }; int CreateItem(HWND hwndList, ITEMS *itm, int iCol) { LVITEM lvi; for(int i = 0; i < iCol ; i++) { lvi.mask = LVIF_TEXT; lvi.iItem = i; lvi.iSubItem = 0; lvi.pszText = itm[i].iItem; ListView_InsertItem(hwndList, &lvi); }; return iCol; }Ich habe 3 Spalten^^
http://www.imagespell.com/oimg/95ddc1be25f45d911e309fc5431d188b.jpg
Aber ich will, dass alle 3 Items nebeneinander stehen (in jede Spalte ein)
I-wo habe ich da einen denkfehler ... -.-
-
Die erste Spalte enthält immer das Item, rechts davon werden die SubItems angezeigt. Du musst also die SubItems dann setzen.
-
Jetzt habich das so:
int CreateItem(HWND hwndList, ITEMS *itm, int iCol) { LVITEM lvi; for(int i = 0; i < iCol ; i++) { lvi.mask = LVIF_TEXT; lvi.iItem = 0; lvi.iSubItem = i; lvi.pszText = itm[i].iItem; ListView_InsertItem(hwndList, &lvi); //if (ListView_InsertItem(hwndList, &lvi) == -1) //return FALSE; }; return iCol; }Aba jetzt sieht es so aus:
http://www.imagespell.com/show.php?id=c1792cb3bd01ead3a1707ad12cc606d3.jpg
...Also wenn ich richtig verstehe ist iSubItem immer die Spalte (also Spalte 1,2,3) aba warum geht das den nicht ^^?? i ändert sich bei jedem durchgang um 1, dh er müsste jede Spalte bis 3 ausfüllen ....
-
msdn schrieb:
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.
Probiers mal stattdessen mit ListView_SetItemText() wenn iSubItem>0 ist.
-
Juhu!! Es klappt!!
Ich habe zwei Versionen:
Einmal so:void CreateItem(HWND hwndList, ITEMS *itm, int iCol) { LVITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = itm[0].iItem; ListView_InsertItem(hwndList, &lvi); for(int i = 0; i < iCol ; i++) { lvi.iItem=0; lvi.iSubItem=i; lvi.pszText = itm[i].iItem; ListView_SetItem(hwndList, &lvi); }; }und einmal so:
void CreateItem(HWND hwndList, ITEMS *itm, int iCol) { LVITEM lvi; lvi.mask = LVIF_TEXT; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = itm[0].iItem; ListView_InsertItem(hwndList, &lvi); for(int i = 0; i < iCol ; i++) { ListView_SetItemText(hwndList, 0, i, itm[i].iItem); }; }Beide funktionieren einwandfrei^^
Ich denk mal die erste Lösung ist besser weil msdn die zweite nur als Alternative vorgeschlagen hat ^^thx