开发者

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

开发者 https://www.devze.com 2023-03-09 23:10 出处:网络
I have set the combo-box data to \"first;second;third\" in the resource editor, but when I compile the program, the co开发者_JAVA技巧mbo-box is totally empty, I can\'t see there any items at all.

I have set the combo-box data to "first;second;third" in the resource editor, but when I compile the program, the co开发者_JAVA技巧mbo-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 ?


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


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


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.


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);

0

精彩评论

暂无评论...
验证码 换一张
取 消