Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MFC Combo-Box Control is not showing the full list of items when I click the drop-down menu

I'm coding an app in MSVS 2008, which has a ComboBox control which I initialize thru the code as below:

static char*                    OptionString[4] = {"Opt1",
                                                   "Opt2",
                                                   "Opt3",
                                                   "Opt4"};


BOOL CMyAppDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE);   // Set big icon
 SetIcon(m_hIcon, FALSE);  // Set small icon

    // TODO: Add extra initialization here

    m_Option.AddString(OptionString[0]);
    m_Option.AddString(OptionString[1]);
    m_Option.AddString(OptionString[2]);
    m_Option.AddString(OptionString[3]);
    m_Option.SetCurSel(0);

    return TRUE;  // return TRUE  unless you set the focus to a control
}

In the above code, m_Option is the Control variable for the ComboBox Control.

Now, when I build the app and click the down-arrow, the drop-down box shows the first option ONLY(since I've selected that thru my code). But, if i press down-arrow key on keyboard, it cycles thru the options in the order I've inserted, but never does it show more than 1 option in the box. So, In case an user wants to select option3, he has to cycle through options 1 and 2 !! Though once I select any option using the keyboard, the appropriate event handlers are fired, I'm miffed by this behaviour , as is understandable.

I'm listing the properties of the combo-box control as well - only the properties that are true(rest are set to false):

  1. Type - Dropdown
  2. Vertical Scrollbar
  3. Visible Tabstop

This has bugged me for weeks now. Can anyone pls enlighten me ?

like image 880
TCSGrad Avatar asked Mar 25 '10 05:03

TCSGrad


People also ask

Which property makes the combobox to be displayed with a textbox and the list box which does not drop down?

You can get or set the combo box's selected item by using the SelectedItem property, and get or set the index of the selected item by using the SelectedIndex property.

How do you use combo boxes in MFC?

The selection in the list box of a combo box is about to be changed as a result of the user either clicking in the list box or changing the selection by using the arrow keys. The combo box receives the input focus. Let us look into an example of Radio button by creating a new MFC dialog based application.

How to use combo box and list box in visual basic?

Drag and drop a combo box to store the items, a list box to display the selected items, four button controls to add to the list box with selected items, to fill the combo box, to sort the items and to clear the combo box list, respectively. Add a label control that would display the selected item.

What is list box and combo box?

Generally, a combo box is appropriate when there is a list of suggested choices, and a list box is appropriate when you want to limit input to what is on the list. A combo box contains a text box field, so choices not on the list can be typed in. The exception is when the DropDownStyle property is set to DropDownList.


2 Answers

In the dialog layout designer, while designing the dialog, click the "down arrow" on the combobox. You can then drag down on the bottom of the combobox's outline to increase its height.

like image 84
jwismar Avatar answered Oct 06 '22 00:10

jwismar


We can programmatically modify dropdown height as:

CRect rctCmbCountry, rctDropDownCountry;
m_Cmb_Country.GetClientRect(&rctCmbCountry); 
m_Cmb_Country.GetDroppedControlRect(&rctDropDownCountry); 
itemHeight = m_Cmb_UI_Country.GetItemHeight(-1); 
m_Cmb_UI_Country.GetParent()->ScreenToClient(&rctDropDownCountry); 
rctDropDownCountry.bottom = rctDropDownCountry.top + rctCmbCountry.Height() + itemHeight * iNoOfITemToShowInComboDropDown; 
m_Cmb_UI_Country.MoveWindow(&rctDropDownCountry);

reference: http://codetechnic.blogspot.com/2012/04/vc-mfc-how-to-set-combobox-dropdown.html#:~:text=1)%20Designer%20%2D%20through%20the%20designer,you%20it's%20anything%20but%20intuitive.

like image 20
suprit Avatar answered Oct 06 '22 01:10

suprit