CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 1999
    Location
    Sweden
    Posts
    15

    Combobox, showing entire list at all times

    A combobox, type 2-Dropdown-list, automatically invokes a vertical scrollbar when the number of listitems exceeds 8. Is there a way to prohibit this behaviour forcing it to show the entire list or a number of my choice?



    Regards

    Patrik

  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Combobox, showing entire list at all times

    You can increase the size of the Drop Down List using the SetWindowPos API, eg.

    private Type RECT
    Left as Long
    Top as Long
    Right as Long
    Bottom as Long
    End Type

    private Declare Function GetWindowRect Lib "user32" (byval hwnd as Long, lpRect as RECT) as Long
    private Declare Function SetWindowPos Lib "user32" (byval hwnd as Long, byval hWndInsertAfter as Long, byval x as Long, byval y as Long, byval cx as Long, byval cy as Long, byval wFlags as Long) as Long

    private Const SWP_FRAMECHANGED = &H20
    private Const SWP_NOMOVE = &H2
    private Const SWP_NOZORDER = &H4

    private Sub SetComboDropSize(byval lHwnd as Long, byval lHeight as Long)
    Dim tRECT as RECT
    Call GetWindowRect(lHwnd, tRECT)
    SetWindowPos lHwnd, 0, 0, 0, tRECT.Right - tRECT.Left, lHeight, SWP_NOMOVE Or SWP_NOZORDER Or SWP_FRAMECHANGED
    End Sub

    private Sub Form_Load()
    'set Drop Height to display 16 Items..
    Call SetComboDropSize(Combo1.hwnd, 240)
    for i = 1 to 16
    Combo1.AddItem "Item" & i
    next
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Join Date
    Sep 1999
    Location
    Sweden
    Posts
    15

    Re: Combobox, showing entire list at all times

    Bullseye!

    Thanks a lot Aaron. May Santa reward you generously.


    Regards

    Patrik Fällman, Luleå, Sweden

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

Featured