Archived

This topic is now archived and is closed to further replies.

antiMATTER

populating a combo box on a dialog box created in Visual C++ 6

Recommended Posts

How would I add/delete text to/from a combo box that I''ve placed on a dialog box in Visual C++ 6? I''m thinking I need to send a message to the comb box with additions and deletions but I don''t know if this is how it''s done or what function would do this. thanks

Share this post


Link to post
Share on other sites
To add text to a combo box, you can use the SendMessage() function with the handle of the combo box. The CB_ADDSTRING message can be used to add text, and CB_DELETESTRING message can be used to remove text. Depending on how you created the dialog, you might be able to use the GetDlgItem() function to get the combo box''s handle.

Share this post


Link to post
Share on other sites
Exactly as SiCrane said.

Additionally, If you''re using MFC you can add a CComboBox member variable to your dialog class, and call its functions AddString/DeleteString on it.

Share this post


Link to post
Share on other sites
Thanks for the quick replies.

This is what I''m trying but it doesn''t work. Any ideas?

SendMessage(GetDlgItem(models->getHandle(),IDC_MODELS_COMBO),CB_ADDSTRING,0,(LPARAM) "test");

Share this post


Link to post
Share on other sites
Well, first I would split the call into separate lines. Check to make sure that the call to GetDlgItem() is returning non-NULL. If it is NULL check GetLastError() for an error code. Then check the return value of SendMessage() to see if it''s returning CB_ERR or CB_ERRSPACE.

Share this post


Link to post
Share on other sites
It''s working. My bad. My combo boxes drop down list wasn''t pulled down in the resource editor. So when I was checking for values in the drop down list I wasn''t seeing anything.

THANKS!

Share this post


Link to post
Share on other sites
ok... let''s elaborate a bit on this. I''m now able to add and delete values. How do I tell which value is the current selected value? How would I delete the current selected value? Right now when I delete it just deletes the item at the top of the list, which is sorted in alphabetical order.

Share this post


Link to post
Share on other sites
quote:
Original post by antiMATTER
It''s working. My bad. My combo boxes drop down list wasn''t pulled down in the resource editor. So when I was checking for values in the drop down list I wasn''t seeing anything.



This is a common problem for new Win32 programmers

Share this post


Link to post
Share on other sites