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
Printable View
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
You need to use SendMessage and the CB_SETDROPPEDWIDTH constant....
Of course you will need to adjust the width according to the longest text in your combobox.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