Solved

CComboBox dropdown does not work

Posted on 2003-10-30
13
543 Views
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;

m_cComboS->Create( WS_CHILD|WS_VISIBLE|CBS_SORT| WS_TABSTOP|WS_VSCROLL|CBS_DROPDOWN,  CRect(131,96,376,92), this, IDC_MY_COMBO);

That works  and I can add strings.

      m_cComboS->InitStorage(25, 50);

      CString test = "1234567890";

      for ( int i=0; i<25; i++)
      {
        m_cComboS->AddString(test);
      }

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)
      this->ShowDropDown(TRUE);
}

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.

0
Comment
Question by:hansw77041
  • 7
  • 5
13 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
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
0
 

Author Comment

by:hansw77041
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.



0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9652449
You should have a variable of type C_ComboBox.
Did you set the drop height of the combo in the resource editor?
0
 
LVL 44

Expert Comment

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

// Dialog Data
      //{{AFX_DATA(CMyPropertyPage1)
      enum { IDD = IDD_PROPPAGE1 };
      CBusinessYearCombo      m_cmboBusinessYear;
      CArrowKeyEdit      m_ctlDate;

and this from the cpp
void CMyPropertyPage1::DoDataExchange(CDataExchange* pDX)
{
      CPropertyPage::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CMyPropertyPage1)
      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.
0
 

Author Comment

by:hansw77041
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.
}


0
 
LVL 44

Expert Comment

by:AndyAinscow
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:hansw77041
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

m_cmboBusinessYear.SubclassDlgItem(IDC_COMBO_BUSINESS_YEAR,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.



0
 
LVL 44

Expert Comment

by:AndyAinscow
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?
0
 

Author Comment

by:hansw77041
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.

0
 
LVL 44

Expert Comment

by:AndyAinscow
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?

0
 

Author Comment

by:hansw77041
ID: 9653342
Andy,
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.

hansw


0
 
LVL 9

Accepted Solution

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

m_cComboS->Create( WS_CHILD|WS_VISIBLE|CBS_SORT| WS_TABSTOP|WS_VSCROLL|CBS_DROPDOWN,  CRect(131,96,376,192), this, IDC_MY_COMBO);

0
 
LVL 44

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now