Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


CComboBox dropdown does not work

Posted on 2003-10-30
Medium Priority
Last Modified: 2013-11-20
I created a control. Based upon CComboBox.

class C_ComboBox : public CComboBox
  rest of this code no shown for brevity.

Then I use it in a dialog as follows.

C_ComboBox * m_cComboS;

m_cComboS = (C_ComboBox*)new C_ComboBox;


That works  and I can add strings.

      m_cComboS->InitStorage(25, 50);

      CString test = "1234567890";

      for ( int i=0; i<25; i++)

int NumItems = m_cComboS->GetCount();

NumItems is equal to 25. So I assume 25 strings have been added.

Now comes the problem. I can’t get the drop down to show.

When I click the “down arrow  button” next to the edit field I expected to see the list of string that got added.

That does not work.

If I handle the       ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)

void C_ComboBox::OnDropdown()
    int Drop = this->GetDroppedState();
    if (!Drop)

Drop is always 0 and ShowDropDown(TRUE); gets called until a stack overflow happens.

What did I do wrong…
If I use a regular CComboBox directly in the dialog and set the dropdown list height in the resource editor it works just fine.  
I Created the C_ComboBox so that I could get to the Pop-up menu feature.

Question by:hansw77041
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
  • 7
  • 5
LVL 45

Expert Comment

ID: 9652131
Create it on the dialog with the resource editor.
With the class wizard create a member variable m_cComboS of type CComboBox
Edit the .h file and replace the CComboBox with C_ComboBox
to read

C_ComboBox m_cComboS;

Then it should be OK

Author Comment

ID: 9652384
Thanks for the help, but it does not solve the problem.

I end up with a CComboBox and the drop down list does not appear.

LVL 45

Expert Comment

ID: 9652449
You should have a variable of type C_ComboBox.
Did you set the drop height of the combo in the resource editor?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 45

Expert Comment

ID: 9652510
This is a snippet from a header file of mine

// Dialog Data
      enum { IDD = IDD_PROPPAGE1 };
      CBusinessYearCombo      m_cmboBusinessYear;
      CArrowKeyEdit      m_ctlDate;

and this from the cpp
void CMyPropertyPage1::DoDataExchange(CDataExchange* pDX)
      DDX_Control(pDX, IDC_COMBO_BUSINESS_YEAR, m_cmboBusinessYear);
      DDX_Control(pDX, IDC_EDIT1, m_ctlDate);

The CBusinessYearCombo is based on a CComboBox, the CArrowKeyEdit on a CEdit.

Author Comment

ID: 9652545
Yes I can make a ComboBox the way you descirbe it here, and that works just fine, but that is not what I need to do.

I want a class so that I can add handlers for the popup menu

class C_ComboBox : public CComboBox
  rest of this code not shown for brevity.

LVL 45

Expert Comment

ID: 9652582
Yes but if you have a member variable of type C_ComboBox as I described then it is a C_ComboBox with ALL of the functionality.

My CBusinessYearCombo and CArrowKeyEdit vars have functions, that I can call, over and above the normal base class functionality.

Does doing this allow the drop arrow to drop the list part? Yes or No.
I hope the answer is yes.

Then. Are you saying you can't get your popup menu?  If you are the problem is in your C_ComboBox (or elsewhere) not in the creation of the variable you have in your dialog.

Author Comment

ID: 9652667
Yes I know I can access the normal functionality of the combobo through such a variable.

However I need to add three extra items to the popup menu, and to do that using the standard VC++ add-in components, the pop-up needs a class.

BTW The better way is to subclass the control like this


Anyway that is not a solution to this problem.

I made a class that almost works, in fact the popup menu works fine.
Adding string works fine, at least it reports there are 25 items and I can get at all 25 strings so I know the control is working that far.
I just cannot get the list to drop down and display the 25 strings that have been added.

Adding a handler ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown) to the class blows the stack and
calling ShowDropDown(TRUE); in the handler does not work.

LVL 45

Expert Comment

ID: 9652788
I don't see why you should require a ON_CONTROL_REFLECT handler.

For clarification.
If you created it in the resource editor and had a var in the .h file
CComboBox m_cComboS;
Does it fill with strings and display the drop down when you click the drop arrow (and press the F4 key if the combo has the focus).

IF yes then please remove the ON_CONTROL_REFLECT handler, set the h file declaration to C_ComboBox m_cComboS and retry.
At this point does it not display the drop list?

Author Comment

ID: 9652856
Yes I can create a normal CComboBox they way you describe ( and have been doing that for many years.), and can access the normal functionality of it.
Of course it displays the strings. I have no problem using a CComboBox the way you describe it.

I think I am not explaining this welll enough, let me try one more time.

To be able to add a popup menu I need a class where the VC Studio add-in can place the code for the popup menu.
When I create and class based upon the CComboBox class I can insert a popup menu and that works fine.

However I cannot get the drop down list to display.

LVL 45

Expert Comment

ID: 9652959
Thanks, one is never sure of the abilities of the person asking the question hence I have tried to do it in small steps, also to help stop me missing something obvious.

Would it be a great problem for you to have the PopUp menu in the dialog rather than the combo?  (I know it separates the functionality but what does the popup menu do in terms of functionality - is it specific to the combo or for the owner of the combo..).  If not you could use the dlg instead of your C_ComboBox class.

'When I create and class based upon the CComboBox class I can insert a popup menu and that works fine. '
Do you mean you right click on the combo and it shows the popup menu? And the F4 key?
One uses the mouse the other the keyboard - is the problem just with the mouse?


Author Comment

ID: 9653342
thanks for the reply.

Well I was kind of thinking it's time to make my own version of the CComboBox with popup menu so that I don't have to re-create it every time...

So to answewr your question. Yes I want the popup handling in the new class, so that everyting is in one basket and can easily be reused.

Yes the popup is the popup you get when right clicking on the ComboBox.



Accepted Solution

Priyesh earned 2000 total points
ID: 9655033
Increase the height while you create, instead of 92, try 192?


LVL 45

Expert Comment

ID: 9655892
Does the drop down work if you remove the popup menu code from your C_ComboBox?

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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