[RESOLVED] ComboBox Drop list question
I have searched and haven't found the answer.
In C, you can change the size of the List area during design, by selecting the down arrow. This changes the re-sizable area to list. Then you can drag how long the list can be.
In VB6, it appears you can only ever change the size of the combobox. Is there an easy way to change how large the list area will be? I would like to make it long enough, that there is no scroll bar.
Re: ComboBox Drop list question
Are you talking about its length or its width?
Perhaps a listbox would be better for you.
Re: ComboBox Drop list question
I am talking about the length of the List area. I want it long enough to not have a vertical scroll bar.
I have 2 items more than it likes, and it adds a vertical scroll bar. I would like to have the list area, long enough to show all items.
Re: ComboBox Drop list question
Re: ComboBox Drop list question
Thanks Bruce, that is exactly what I was looking for.
Re: [RESOLVED] ComboBox Drop list question
I think that may not work under Vista if you are running an app using a manifest to implement 'XP/Vista' styles. Please test the previous advice first and if you have any trouble try;
In a module:
Code:
Private Type DLLVERSIONINFO
cbSize As Long
dwMajor As Long
dwMinor As Long
dwBuildNumber As Long
dwPlatformID As Long
End Type
Private Declare Function CommonControlsVer Lib "Comctl32.dll" Alias "DllGetVersion" (pdvi As DLLVERSIONINFO) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Function GetCommonControlsVer() As String
Dim tDVI As DLLVERSIONINFO
tDVI.cbSize = Len(tDVI)
On Error Resume Next 'DllGetVersion is not implemented in very early (pre v4.71) versions of comctl32.dll so an error is possible
CommonControlsVer tDVI
On Error GoTo 0 'if there is an error "0.0" is returned
GetCommonControlsVer = tDVI.dwMajor & "." & tDVI.dwMinor
'ref http://msdn.microsoft.com/en-us/library/bb776779(VS.85).aspx
'4.71 Internet Explorer 4.0
'5.81 Comctl32.dll Windows 2000 and Windows Me. See note 3. (Win 95 with IE5.5 returns 5.81)
'5.82 Comctl32.dll Windows XP and Windows Vista. See note 4
'Note 4: ComCtl32.dll version 6 is not redistributable. If you want your application to use ComCtl32.dll version 6,
' you must add an application manifest that indicates that version 6 should be used if it is available.
End Function
Public Sub ComboHeightSet(oComboBox As ComboBox, ByVal Nrows%, Optional onframe As Boolean = False, Optional cbWidth%)
'oComboBox the ComboBox of interest
'Nrows% the number of rows required in the dropdown
'onframe set to True in the call only if oComboBox is on a Frame Control
'cbWidth% the width required in twips; if you want to change it
Dim OldScaleMode%, rowheight%
Dim lNewHeight&
Dim lret&
Const CB_GETITEMHEIGHT = &H154
Const CBM_FIRST = &H1700 'Combobox control messages
Const CB_SETMINVISIBLE = (CBM_FIRST + 1)
With oComboBox
'XP SP3 typically has Comctl32.dll v6.0, Vista SP1 has Comctl32.dll v6.16 (ref 17 July 2008)
'CB_SETMINVISIBLE does not seem to work with v6.0 as advertised
If Val(GetCommonControlsVer) >= 6.16 Then
'typically Vista and there is a manifest file specifying Comctl32.dll v6.0, default number of rows is 30
' note: if a manifest has been used but IsThemeActive() = 0 (Themes are disabled) the combo looks like
' an old style one but we still need to talk to it like this ...
SendMessage .hWnd, CB_SETMINVISIBLE, Nrows, 0 '
Else
'XP and previous, or Vista with no manifest file, default number of rows is 8
' Change the ScaleMode on the parent to Pixels.
OldScaleMode = .Parent.ScaleMode
.Parent.ScaleMode = vbPixels
rowheight = SendMessage(.hWnd, CB_GETITEMHEIGHT, 0, 0)
lNewHeight = Nrows * rowheight + .Height + 2
' Resize the combo box window.
If Not onframe Then
MoveWindow .hWnd, .Left, .Top, .Width, lNewHeight, True
Else
'frame is unaffected by .Parent.ScaleMode and remains dimensioned in Twips so..
MoveWindow .hWnd, .Left / Screen.TwipsPerPixelX, .Top / Screen.TwipsPerPixelY, .Width / Screen.TwipsPerPixelX, lNewHeight, True
End If
' Replace the old ScaleMode
.Parent.ScaleMode = OldScaleMode
End If
If cbWidth > 0 Then
Const CB_SETDROPPEDWIDTH As Long = &H160&
SendMessage .hWnd, CB_SETDROPPEDWIDTH, cbWidth / Screen.TwipsPerPixelX, 0
End If
End With
End Sub