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

CComboBox display list

So I have this combo box that I created on my dialog.  I'm adding lots and lots of strings to it.  When I click on the down arrow, it drops down this tiny list selector with really tiny up and down buttons.  I was hoping when you clicked on the down arrow, it would drop down with like 5 or 6 strings showing, and a nice scrollbar on the side, instead of the extremely small one i got.  How do I fix this??? Thanks,
  • 2
1 Solution
Open dialog editor, click on combobox arrow, and resize combobox. This defines size of dropdown list.
if you are looking to set number of lines in dropdown box of combo then following function will  Set the proper number of lines in a drop-down list combo box.

void set_DropDownSize(CComboBox& box, UINT LinesToDisplay)
    ASSERT(IsWindow(box));      // Window must exist or SetWindowPos won't work

    CRect cbSize;                  // current size of combo box
    int Height;            // new height for drop-down portion of combo box

    Height = box.GetItemHeight(-1);      // start with size of the edit-box portion
    Height += box.GetItemHeight(0) * LinesToDisplay;      // add height of lines of text

    // Note: The use of SM_CYEDGE assumes that we're using Windows '95
    // Now add on the height of the border of the edit box
    Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges

    // The height of the border of the drop-down box
    Height += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges

    // now set the size of the window
    box.SetWindowPos(NULL,0, 0,cbSize.right, Height,  SWP_NOMOVE | SWP_NOZORDER );

with above function you may programatically change number of lines in dropdown combobox.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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