
Number of visible items in listbox control
Quote:
> Yes Rob, I always mix them up!! Ofcourse I mean the combobox. There
are so
> many items available without scrolling. I use them for a time
registration
> app. and they want to be able to pick 8 hours without having to
scroll. Only
> the numbers 0 to 7 are visible without scrolling :-(
As for changing the number of lines displayed in a ComboBox, consider
the following code which allows you to modify the number of items
displayed...
Put (paste) the following declarations and procedure in a Module
(Project/AddModule from VB's menu):
Quote:
>>>>>Start Of Paste<<<<<
Private Declare Function SendMessageLong _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Function GetWindowRect _
Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) _
As Long
Private Declare Function ScreenToClient _
Lib "user32" _
(ByVal hwnd As Long, _
lpPoint As POINTAPI) _
As Long
Private Declare Function MoveWindow _
Lib "user32" _
(ByVal hwnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long
Private Const CB_GETITEMHEIGHT = &H154
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Public Sub SetComboBoxHeight(ComboBoxIn As ComboBox, _
NumberOfItemsTall As Long)
Dim Point As POINTAPI
Dim Rectangle As RECT
Dim ComboBoxWidth As Long
Dim NewComboBoxHeight As Long
Dim EditAreaHeight As Long
Dim OldScaleMode As Long
Dim ListAreaHeight As Long
ComboBoxWidth = ComboBoxIn.Width \ Screen.TwipsPerPixelX
ListAreaHeight = SendMessageLong(ComboBoxIn.hwnd, _
CB_GETITEMHEIGHT, 0, 0)
EditAreaHeight = SendMessageLong(ComboBoxIn.hwnd, _
CB_GETITEMHEIGHT, -1, 0)
NewComboBoxHeight = ListAreaHeight * NumberOfItemsTall + _
2 * EditAreaHeight
GetWindowRect ComboBoxIn.hwnd, Rectangle
Point.x = Rectangle.Left
Point.y = Rectangle.Top
ScreenToClient ComboBoxIn.Container.hwnd, Point
MoveWindow ComboBoxIn.hwnd, Point.x, Point.y, _
ComboBoxWidth, NewComboBoxHeight, True
End Sub
Quote:
>>>>>End Of Paste<<<<<
Although you can specify less than eight items, you will get eight which
seems to be the minimum number of items displayable. Below is an example
showing a combo box being reset to the number contained in a text box.
SetComboBoxHeight Combo1, CLng(Text1.Text)
Rick - MVP