Adjust Combo Box Drop-down Width

Adjust Combo Box Drop-down Width

Due to limited space on a form, you sometimes must keep the width of combo boxes small. Because a combo box lacks a horizontal scrollbar, some text might remain hidden. Use these functions to retrieve the current size of a drop-down and to resize the drop-down portion of the combo box as needed at run time. Add this code to a BAS module and call it from wherever convenient-perhaps during your Form_Load procedure:

 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 LongPrivate Const CB_GETDROPPEDWIDTH = &H15FPrivate Const CB_SETDROPPEDWIDTH = &H160Private Const CB_ERR = -1Public 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 IfEnd FunctionPublic 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 IfEnd Function
See also  Monetize TikTok For Your Business

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist