Wednesday, April 01, 2009

Controlling DisplayCount in ComboBoxes

The DisplayCount property of the ComboBox class controls how many items the user sees when the ComboBox is dropped down. Normally this is a fixed value, so even though there may be plenty of room to display more items, the user can only see so many and has to scroll to see more.

I like to set DisplayCount dynamically based on how much room there is between the ComboBox's position and the bottom of the screen. I used the following code in the DropDown method of my base ComboBox class to handle this:

* Set DisplayCount to an appropriate value based on how much room there is
* below the form.

local lnHeight
lnHeight = iif(Thisform.ShowWindow = 2 or ;
(pemstatus(Thisform, 'Desktop', 5) and Thisform.Desktop), sysmetric(2), ;
This.DisplayCount = max(ceiling((lnHeight - Thisform.Top - ;
objtoclient(This, 1))/This.Height), 7)

1 comment:

Mark Letheren said...

Excellent idea