Private Sub Form_Load()
Dim i As Integer
Dim max_wid As Long
' See how wide the widest ComboBox entry is.
Me.ScaleMode = vbPixels
For i = 0 To Combo1.ListCount - 1
If max_wid < TextWidth(Combo1.List(i)) Then
max_wid = TextWidth(Combo1.List(i))
End If
Next i
' Set the width for the dropdown list, adding a margin.
SendMessage Combo1.hwnd, _
CB_SETDROPPEDWIDTH, max_wid + 10, 0
' Select the first choice.
Combo1.ListIndex = 0
End Sub
|