NO

Author Topic: Listview control item problem  (Read 6098 times)

halsten

  • Guest
Listview control item problem
« on: November 19, 2008, 09:34:59 AM »
I am trying to add items to my listview, but they always show up empty. Here's what am using:

Code: [Select]
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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Listview control item problem
« Reply #1 on: November 19, 2008, 01:44:36 PM »
Maybe like this
Code: [Select]
lvI.iItem = ListView_GetItemCount(hWndListView);
g_iItem = 0;
May the source be with you

halsten

  • Guest
Re: Listview control item problem
« Reply #2 on: November 19, 2008, 02:49:49 PM »
No it's not working. The problem is that the items are empty strings.

Offline DMac

  • Member
  • *
  • Posts: 272
Re: Listview control item problem
« Reply #3 on: November 19, 2008, 06:03:28 PM »
Take a look at the attached demo.

Perhaps this will help.

Regards,
DMac
No one cares how much you know,
until they know how much you care.

halsten

  • Guest
Re: Listview control item problem
« Reply #4 on: November 19, 2008, 06:37:02 PM »
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

Offline DMac

  • Member
  • *
  • Posts: 272
Re: Listview control item problem
« Reply #5 on: November 19, 2008, 07:13:50 PM »
Try this:

Code: [Select]
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);
}
« Last Edit: November 19, 2008, 07:23:13 PM by DMac »
No one cares how much you know,
until they know how much you care.

halsten

  • Guest
Re: Listview control item problem
« Reply #6 on: November 19, 2008, 11:02:40 PM »
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.

Offline DMac

  • Member
  • *
  • Posts: 272
Re: Listview control item problem
« Reply #7 on: November 20, 2008, 02:48:43 AM »
ok fixed.

Main problem:
Code: [Select]
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.

No one cares how much you know,
until they know how much you care.

halsten

  • Guest
Re: Listview control item problem
« Reply #8 on: November 20, 2008, 08:01:45 AM »
Thanks a lot DMac. It worked perfectly! Much appreciated.