Results 1 to 6 of 6

Thread: [RESOLVED] ComboBox Drop list question

  1. #1

    Thread Starter
    Member
    Join Date
    May 2009
    Location
    Victoria, BC
    Posts
    36

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ComboBox Drop list question

    Are you talking about its length or its width?

    Perhaps a listbox would be better for you.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2009
    Location
    Victoria, BC
    Posts
    36

    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.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: ComboBox Drop list question


  5. #5

    Thread Starter
    Member
    Join Date
    May 2009
    Location
    Victoria, BC
    Posts
    36

    Re: ComboBox Drop list question

    Thanks Bruce, that is exactly what I was looking for.

  6. #6
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width