Hi i have this script in VB, so if you could translate, you can use it.
this code keeps the combo size, and only the dropdown list is wider than the
combo itself, and it matches the longest item in the list.
Private Function GetCboWidth(ByVal myIndex As Integer)
Dim cwidth As Long
Dim cnt As Long
Dim NumOfChars As Long
Dim LongestComboItem As Long
Dim avgCharWidth As Long
Dim NewDropDownWidth As Long
For cnt = 0 To cboCombo(myIndex).ListCount - 1
NumOfChars = SendMessage(cboCombo(myIndex).hwnd, CB_GETLBTEXTLEN, cnt,
ByVal 0)
If NumOfChars LongestComboItem Then LongestComboItem = NumOfChars
Next
avgCharWidth = GetFontDialogUnits()
NewDropDownWidth = (LongestComboItem - 2) * avgCharWidth
Call SendMessage(cboCombo(myIndex).hwnd, CB_SETDROPPEDWIDTH,
NewDropDownWidth, ByVal 0)
cwidth = SendMessage(cboCombo(myIndex).hwnd, CB_GETDROPPEDWIDTH, 0, ByVal
0)
End Function
"Andrew" <An****@discussions.microsoft.comwrote in message
news:F9**********************************@microsof t.com...
Hello, friends,
We use System.Windows.Forms.ComboBox in our c#.net 2005 app. We want to
make
the dropdown list wider than the comboBox's width. (Some items in the
dropdown list have more characters that go beyond the comboBox's width).
How do we do it? Thanks a lot.