Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
There are nearly 50 items in my combo box. I want to load them all to combo but want to display few (max. 10) items only.
Can it be set so that when user clicks the combo, few items are shown, when clicked again, all are displayed?

Thanks
Posted

1 solution

To control the number of items displayed in a comboBox you can use the MaxDropDownItems[^] property. But it won't behave the way you expect it to unless you also adjust the IntegralHeight[^] property. E.g.
VB
ComboBox3.IntegralHeight = False
ComboBox3.MaxDropDownItems = 10

The second part of your requirement is a little strange but can be achieved by simply resetting IntegralHeight = True. You have to be careful where to place this - if you use the Click event for example the Dropdown will briefly show then close again (don't blink or you'll miss it!). This is probably the best idea
VB
Private Sub ComboBox3_DropDownClosed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.DropDownClosed
    ComboBox3.IntegralHeight = True
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900