Results 1 to 2 of 2

Thread: Combo Box Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217

    Combo Box Question

    I know I've seen the code before, but I have a combo box, and the text is to wide for the control, and I need the combo box to expand out when clicked, so that the full text can show. Thanks

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    You need to use SendMessage and the CB_SETDROPPEDWIDTH constant....

    Code:
    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 Const CB_SETDROPPEDWIDTH = &H160
    
    Private Sub Form_Load()
     Dim s As String
     Dim width As Long
        s = "Realllllly Long Text"
        Combo1.width = 750
        Combo1.AddItem s
        width = Me.TextWidth(s)
        SetComboDroppedWidth Combo1, width
    End Sub
    
    Private Sub SetComboDroppedWidth(c As ComboBox, w As Long)
    Dim iPixW As Long
    
    iPixW = Me.ScaleX(w, vbTwips, vbPixels)
    
    Debug.Print SendMessage(c.hwnd, CB_SETDROPPEDWIDTH, iPixW, 0)
    
    End Sub
    Of course you will need to adjust the width according to the longest text in your combobox.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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