Steve
Steve

Reputation: 6424

Cannot restrict vertical size of ComboBox control

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?

Upvotes: 1

Views: 2670

Answers (2)

IInspectable
IInspectable

Reputation: 51345

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='*'\"")

Upvotes: 2

saroj kumar
saroj kumar

Reputation: 330

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.

Upvotes: 1

Related Questions