Sorry, I was pressed for time yesterday. Here's the whole thing in VB:
Dim g As System.Drawing.Graphics = ComboBox1.CreateGraphics
Dim maxWidth As Double = 0.0F
For Each o As Object In ComboBox1.Items
Dim w As Double = g.MeasureString(o.ToString(), ComboBox1.Font).Width
If (w > maxWidth) Then
maxWidth = w
End If
Next
g.Dispose()
ComboBox1.[red]DropDownWidth[/red] = maxWidth + 20
Note the portion in red. As the code was written (using .Width instead of .DropDownWidth), it would increase the size of the combobox control. This change only affects the width of the dropdown box.
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson