• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1553
  • Last Modified:

Accessing a MFC combo box

Hi,

1. how do I get the pointer/reference of a combo box object that I added in the MS VS 2003 GUI editor and that has got the ID "IDC_COMBO1"?

2. how do put some static strings into it's list?

3. how do I restrict the combo box to allow only the strings from the list (no manual typing)?

BTW, I'm a absolutely new to MFC and win32 but have got some C++ expirience.

Thank you for efforts.
0
x4u
Asked:
x4u
  • 4
  • 2
5 Solutions
 
Jaime OlivaresSoftware ArchitectCommented:
go to ClassWizard (Ctrl-W)
select your dialog object
select the "member variables" tab
your control label will appear, select it
press the "Add variable" button, another dialog will appear
here is the trick: write a variable name and in the "category" choose "control"
now your dialog has a proper initialized member you can use to pass any message

0
 
Jaime OlivaresSoftware ArchitectCommented:
to avoid user to "type" another string, just go to dialog GUI editor, select combo box properties, and change style to "Drop list" (not drop down)

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
After creating your control var - m_cmboXYZ you can add strings like this

m_cmboXYZ.AddString("One");
m_cmboXYZ.AddString("Two");

The default behaviour is to sort them, you can stop this in the resource editor - it's one of the settings.
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
Jaime OlivaresSoftware ArchitectCommented:
2. how do put some static strings into it's list?

In the resource editor you can insert your static list in combobox properties, "data" tab.
0
 
x4uAuthor Commented:
Thank you, adding items works fine now.

But the drop down list height seems to be zero, it is appears only a thick black line. I can browse the items with the cursor keys but how do I resize the list box height to a reasonable height? Can I set set it to resize automatically somehow?

BTW, I get is the same behaviour with AddString and when I type the strings into data properties field.
0
 
Jaime OlivaresSoftware ArchitectCommented:
About the control height, it is a common error:
Comboboxes have 2 height: Edit portion height and drop-down list height. You have not resized the second.

Go to dialog GUI editor, select your combobox, the bounding rectangle will be selected, now press on the drop-down arrow, a diferent rectangle will be selected, drag lower boundary to desired size. That's all.
0
 
x4uAuthor Commented:
Ahh, cool thanks. I would never have figuered this out myself. ;-)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now