I am trying to add items to my listview, but they always show up empty. Here's what am using:
static void InsertItem(HWND hwndParent, PCHAR pszAddress, PCHAR pszByteCode, PCHAR pszDisassembly, PCHAR pszComment) {
static HWND hWndListView;
static LV_ITEM lvI;
ZeroMemory(&lvI, sizeof(lvI));
hWndListView = GetDlgItem(hwndParent, IDC_DISASMLIST);
lvI.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvI.iItem = 1;
lvI.iSubItem = 0;
lvI.pszText = (LPWSTR)pszAddress;
ListView_InsertItem(hWndListView, &lvI);
g_iItem = ListView_GetItemCount(hWndListView);
lvI.iSubItem = g_iItem;
lvI.pszText = (LPWSTR)pszByteCode;
ListView_SetItem(hWndListView, &lvI);
g_iItem++;
lvI.iSubItem = g_iItem;
lvI.pszText = (LPWSTR)pszDisassembly;
ListView_SetItem(hWndListView, &lvI);
g_iItem++;
lvI.iSubItem = g_iItem;
lvI.pszText = (LPWSTR)pszComment;
ListView_SetItem(hWndListView, &lvI);
}
Am I doing something wrong? any ideas would be really helpful? Thanks in advance.
Regards,
halsten
Maybe like this
lvI.iItem = ListView_GetItemCount(hWndListView);
g_iItem = 0;
No it's not working. The problem is that the items are empty strings.
Take a look at the attached demo.
Perhaps this will help.
Regards,
DMac
Thanks DMac, I checked the src, and am pretty much doing the same. Any other comments on the code I have posted? No idea what's wrong with it. Thanks in advance.
Regards,
halsten
Try this:
static void InsertItem(HWND hwndParent, PCHAR pszAddress, PCHAR pszByteCode, PCHAR pszDisassembly, PCHAR pszComment) {
static HWND hWndListView;
static LV_ITEM lvI;
static int iSubitem;
ZeroMemory(&lvI, sizeof(lvI));
hWndListView = GetDlgItem(hwndParent, IDC_DISASMLIST);
iSubItem = 0;//<-- subitem 0 == Column 1
lvI.mask = LVCF_TEXT;//<-- only adding text
lvI.iItem = ListView_GetItemCount(hWndListView); //<-- start with the next row
lvI.iSubItem = iSubItem;
lvI.pszText = (LPWSTR)pszAddress;
ListView_InsertItem(hWndListView, &lvI);
iSubItem++
lvI.iSubItem = iSubItem;
lvI.pszText = (LPWSTR)pszByteCode;
ListView_SetItem(hWndListView, &lvI);
iSubItem++;
lvI.iSubItem = iSubItem;
lvI.pszText = (LPWSTR)pszDisassembly;
ListView_SetItem(hWndListView, &lvI);
iSubItem++;
lvI.iSubItem = iSubItem;
lvI.pszText = (LPWSTR)pszComment;
ListView_SetItem(hWndListView, &lvI);
}
Still no effect, the row is added with an empty string. I am going to upload what I have maybe there is something else am doing wrong. Sorry for the inconvenience.
ok fixed.
Main problem:
lvI.mask = LVCF_TEXT; // <-- Should be LVIF_TEXT
Peles C compiler found some other type cast errors I patched them up to get the example to run.
Thanks a lot DMac. It worked perfectly! Much appreciated.