?
Solved

Accessing a MFC combo box

Posted on 2004-08-04
7
Medium Priority
?
1,546 Views
Last Modified: 2013-11-20
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
Comment
Question by:x4u
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1400 total points
ID: 11718075
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
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1400 total points
ID: 11718135
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
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 600 total points
ID: 11718236
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 how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1400 total points
ID: 11718258
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
 
LVL 11

Author Comment

by:x4u
ID: 11719182
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
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 1400 total points
ID: 11719261
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
 
LVL 11

Author Comment

by:x4u
ID: 11719424
Ahh, cool thanks. I would never have figuered this out myself. ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question