Results 1 to 5 of 5

Thread: [RESOLVED] ComboBox dropdown scrollbar height

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Resolved [RESOLVED] ComboBox dropdown scrollbar height

    Hi there,

    I have some issue with the ComboBox Scrollbar height after adding items to it, instead of max. 8 items, it shows me almost all with a long vertical scrollbar.

    Here is the sample code:

    Code:
    Dim itCnt As Integer
    
    For itCnt = 0 To 59
      cboMin.AddItem Format(itCnt, "00")
     Next itCnt
    In the IDE, while running the code is working as it should, but after compiling the code, the vertical scrollbar height increases to 30 items.

    p.s. I'm using "mainfest" from the Resource file.

    How could I fix this issue?

    Thank you for suggestions!

  2. #2
    Hyperactive Member
    Join Date
    Jul 2021
    Posts
    267

    Re: ComboBox dropdown scrollbar height

    Since you are using a manifest for visual-styles, if you want to turn it off for a specific control, do it like this:
    Code:
    Private Declare Function SetWindowTheme Lib "uxtheme.dll" (ByVal hwnd As Long, ByVal pszSubAppName As Long, ByVal pszSubIdList As Long) As Long
    
    Private Sub Form_Load()
    Call SetWindowTheme(cboMin.hwnd, 0, StrPtr(""))
    End Sub
    Last edited by Dry Bone; Mar 4th, 2024 at 01:26 PM.

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: ComboBox dropdown scrollbar height

    Quote Originally Posted by Dry Bone View Post
    Since you are using a manifest for visual-styles, if you want to turn it off for a specific control, do it like this:
    Code:
    Private Declare Function SetWindowTheme Lib "uxtheme.dll" (ByVal hwnd As Long, ByVal pszSubAppName As Long, ByVal pszSubIdList As Long) As Long
    
    Private Sub Form_Load()
    Call SetWindowTheme(cboMin.hwnd, 0, StrPtr(""))
    End Sub
    Thanks Bone for the suggestion, but, yes, it will remove the visual style, but the height of the dropdown is still the same (showing all items), even worse, because now there is no scrollbar in it.

  4. #4
    Hyperactive Member
    Join Date
    Jul 2021
    Posts
    267

    Re: ComboBox dropdown scrollbar height

    Well well well. This was a tough one.
    But the answer is oh so simple.
    You definitely DON'T need to remove the visual style.
    Instead, use CB_SETMINVISIBLE message to set the desired number of items you want the user see.
    This message works only with visual styles.
    Code:
    Private Const CB_SETMINVISIBLE = &H1701&
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    SendMessage cboMin.hWnd, CB_SETMINVISIBLE, 8, 0

  5. #5

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: ComboBox dropdown scrollbar height

    Quote Originally Posted by Dry Bone View Post
    Well well well. This was a tough one.
    But the answer is oh so simple.
    You definitely DON'T need to remove the visual style.
    Instead, use CB_SETMINVISIBLE message to set the desired number of items you want the user see.
    This message works only with visual styles.
    Code:
    Private Const CB_SETMINVISIBLE = &H1701&
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    SendMessage cboMin.hWnd, CB_SETMINVISIBLE, 8, 0
    Oh, somehow it worked!

    Thanks alot!

Tags for this Thread

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