Hi everyone,
could someone tell me how to make a combobox expand whilst it is being clicked so that the dropdown menu is long enough to show data that is longer that the actual combobox..
Thanks.
John Finney
dynamically expanding combobox
Welcome aboard to PureBasic jmf73 
You'll need the full version of PBWin since this uses Win32 API.
You'll need the full version of PBWin since this uses Win32 API.
Code: Select all
If OpenWindow(0, 0, 0, 270, 240, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Resizable ComboBoxGadget") And CreateGadgetList(WindowID(0))
TextGadget(0, 10, 10, 100, 20, "Items to view")
StringGadget(1, 120, 10, 50, 20, "8", #PB_String_Numeric)
ComboBoxGadget(2, 10, 40, 250, 100); -- Add #CBS_NOINTEGRALHEIGHT flag For WinXP
; --> Get 3d border height
vEdge = GetSystemMetrics_(#SM_CYEDGE)
; --> Number of items to view
itemsToView = Val(GetGadgetText(1))
; --> Get height of ComboBox selection field
cbSelectedItemHeight = SendMessage_(GadgetID(2), #CB_GETITEMHEIGHT, -1, 0)
; --> get height of ComboBox item
cbListItemHeight = SendMessage_(GadgetID(2), #CB_GETITEMHEIGHT, 0, 0)
; -- Resize adding 4 units of vEdge (2 for selection field and 2 for dropdown)
ResizeGadget(2, -1, -1, -1, cbSelectedItemHeight + (cbListItemHeight * itemsToView) + vEdge*4)
For a = 1 To 29
AddGadgetItem(2, -1, "ComboBox item " + Str(a))
Next
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = 1
itemsToView = Val(GetGadgetText(1))
If itemsToView > 0 And itemsToView < CountGadgetItems(2)+1
ResizeGadget(2, -1, -1, -1, cbSelectedItemHeight + (cbListItemHeight * itemsToView)+ vEdge*4)
Else
MessageRequester("Error", "enter a number between 1 and " + Str(CountGadgetItems(2)), 0)
SetGadgetText(1, "8")
EndIf
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1

