Click to See Complete Forum and Search --> : ComboBox


August 10th, 1999, 09:45 AM
Hi
I have a combobox control, the width of it is not enough to display the item string, but there is no more space in the form. Does anybody know how to display the data completely when the list shows?
Thanks a lot for any help.

Chris Eastwood
August 10th, 1999, 09:53 AM
This should do the trick, I've been using it for a few years with no problems :

http://www.mvps.org/vbnet/code/listapi/combowidth.htm




Chris Eastwood

CodeGuru - the website for developers
http://www.codeguru.com/vb

Santosh
August 10th, 1999, 09:59 AM
Private Const CB_GETDROPPEDWIDTH = &H15F
Private Const CB_SETDROPPEDWIDTH = &H160
Private Const CB_ERR = -1

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

------------------------------------------
In the form load call

Call SetDropdownWidth(ComboBox.hwnd,GetDropdownWidth(ComboBox.hwnd) * 1.5)

1.5 means drop down width becomes one and half times the actual one.

Public Function GetDropdownWidth(cboHwnd As Long) As Long

Dim lRetVal As Long

'*** To get the combo box drop-down width.

'*** You may use this function if you want

'*** to change the width in proportion

'*** i.e. double, half, 3/4 of existing width.

lRetVal = SendMessage(cboHwnd, CB_GETDROPPEDWIDTH, 0, 0)

If lRetVal <> CB_ERR Then

GetDropdownWidth = lRetVal

'Width in pixels

Else

GetDropdownWidth = 0

End If

End Function

Public Function SetDropdownWidth(cboHwnd As Long, NewWidthPixel As Long) As Boolean

Dim lRetVal As Long

' *** To set combo box drop-down width ***

lRetVal = SendMessage(cboHwnd, CB_SETDROPPEDWIDTH, NewWidthPixel, 0)

If lRetVal <> CB_ERR Then

SetDropdownWidth = True

Else

SetDropdownWidth = False

End If

End Function


Santosh N
Sr. Software Engineer,
Wipro Infotech, India.

August 10th, 1999, 10:29 AM
Thanks a lot.