Click to See Complete Forum and Search --> : adding items to a ListBox does not work


EasyWriter
March 16th, 2006, 09:11 AM
Hello all,

all I want to do is simply add a string to a list box.
When trying to add a string SendMessage() returned 0, but checking the number of list box entries (LB_GETCOUNT) said zero. The item was not added and is hence not displayed in the listbox. Has anyone an explanation for this?

I tried the following code:

HWND hwndList = GetDlgItem(hWnd, IDC_LISTBOX);
SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM) "I am a string");
int numberitems = SendMessage(hwndList, LB_GETCOUNT, 0, 0);


I use the MSVC 6. I created the list box with the built-in resource manager (by simply drag and drop).

Here is the excerpt from the generated .rc file:

CONTROL "List1",IDC_LISTBOX,"SysListView32",LVS_ALIGNLEFT |
WS_BORDER | WS_TABSTOP,69,61,191,91

Mike Harnad
March 16th, 2006, 09:45 AM
"SysListView32" is not a list box. It is a list control that supports different view styles (ie. Report, Small Icon, etc.). You're going to need to change the code you use to access the control by using LVM_ messages, or, change the control to a "listbox".

EasyWriter
March 16th, 2006, 10:00 AM
Hey Mike,

thanks for this hint. I changed the string from "SysListView32" to "listbox" and now it works. Thank you sooo much.

Christian