1
votes

I've created a very simple dialog-based MFC app using VS2010 in an attempt to find a solution to a problem we're having. I've dropped a combobox onto the dialog from the toolbox, and modified the OnInitDialog method to add a whole bunch of items to it.

I would like to restrict the vertical size of the open combobox. It seems that the way to do this using the designer is to click on the drop-down arrow of the combobox control, which switches the kinds of handles available to resize the control, and allows a height to be set. This height does affect the size of the closed combobox, but is supposed to control the size of the opened combobox.

This isn't the case, however. How can the vertical size of the opened drop down be restricted?

2
This works fine for me - clicking the drop-down allows me to select the size of the open combo and has no effect on the closed combo - are you sure you're dragging the correct handle?Roger Rowland
You can call CComboBox::SetMinVisibleItems at runtime to control the height of the dropdown list.IInspectable
@IInspectable - That worked! Thank you. Post that as an answer and I will accept it.Steve
@Roger setting No Integral height to true allows that to work, as @IInspectable pointed out. Thanks for trying it, though :)Steve

2 Answers

1
votes

The steps outlined in Setting the Size of the Combo Box and Its Drop-Down List only have the desired effect if you set the No Integral Height property to True or create the combo box with the CBS_NOINTEGRALHEIGHT style. Unfortunately this usually leads to partially displayed items, as the height is specified in display units.

To get the desired height of the dropdown part of the combo box without partially clipping items you have to set it at runtime by calling CComboBox::SetMinVisibleItems or sending a CB_SETMINVISIBLE message. Both of these are identical where the former uses the MFC-provided member function and the latter is available whether you use MFC or not. To set the number of visible items the application must specify comctl32.dll version 6 in the manifest. To do so add the following to your application manifest:

<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
    ...
</dependency>

If you are using Microsoft Visual C++ 2005 or later, you can add the following compiler directive to your source code instead of manually creating a manifest:

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
1
votes

you can use- CComboBox::SetMinVisibleItems(int);

For seting the minimum number of visible items in the drop-down list of the current combo box control.

By specifying number of visible item in drop-down list you can control the height of drop-down list as you required.