Rookie
Rookie

Reputation: 3793

How to get combo-box display values using the Data field?

I have set the combo-box data to "first;second;third" in the resource editor, but when I compile the program, the combo-box is totally empty, I can't see there any items at all.

Also, how do I set which item is selected by default ? And how do I change the currently selected item programmatically ?

Upvotes: 2

Views: 8838

Answers (4)

Barmak Shemirani
Barmak Shemirani

Reputation: 31599

In "Data" field, enter values separated by semicolon ; as follows:

line1;line2;line3

On initialization, each of these values will show up in a line.

This works in VS 2015, and I think as far back as VS 2008

Upvotes: 1

Ei Thae
Ei Thae

Reputation: 11

For setting value,you can use AddString() method mycombobox.AddString("first"); mycombobox.AddString("second"); mycombobox.AddString("third"); For setting index, you can use SetCurSel() method and set to Default value "first". mycombobox.SetCurSel(0);

Upvotes: 0

Mark Ransom
Mark Ransom

Reputation: 308176

The answer can be found in this article: http://codeguru.earthweb.com/cpp/com-tech/atl/atl/print.php/c3599

The DLGINIT resource added by the resource editor is a list of messages to pass to child controls just after the dialog is created. MFC has code to do this automatically in the ExecuteDlgInit method, so solutions based on MFC will "just work"; everybody else will have to provide their own code for initialization. It also appears that the messages inserted by the dialog editor are based on the 16-bit Windows API and need translation for 32/64-bit Windows.

I would suggest ignoring the initialization data provided by the dialog editor and using the CB_ADDSTRING message to place the initial strings.

Some other good advice here: http://www.flounder.com/combobox.htm

Upvotes: 2

yasouser
yasouser

Reputation: 5177

Checkout this tutorial on Win32 Combo boxes: Introduction to Combo Boxes

If you are using MFC CComboBox class then you need to use the methods AddString() or InsertString() to add elements in the combo box list.

Upvotes: 0

Related Questions