order, MacOS X 10.2 and later offers you the possibility to automatically
sort your ComboBox items. Another goodie in the following example
code demonstrates how to programmatically open the drop down list of
your ComboBox. Unfortunately the example only works for editable
ComboBoxes (with the flag #PB_ComboBox_Editable) because the
underlying API element is a HIComboBox which offers the described
features. PB's non-editable ComboBox utilizes a PopupButton control
which doesn't support these features.
Code: Select all
ImportC ""
HIComboBoxChangeAttributes(HIViewRef.L, AttributesToSet.L, AttributesToClear.L)
HIComboBoxSetListVisible(HIViewRef.L, Visible.L)
EndImport
#kHIComboBoxAutoSortAttribute = 1 << 2
OpenWindow(0, 200, 100, 200, 130, "ComboBoxGadget")
ComboBoxGadget(0, 10, 10, WindowWidth(0) - 20, 100, #PB_ComboBox_Editable)
; ----- Activate ComboBox AutoSort Feature
HIComboBoxChangeAttributes(GadgetID(0), #kHIComboBoxAutoSortAttribute, 0)
; ----- Add unsorted entries
AddGadgetItem(0, -1, "Entry 2")
AddGadgetItem(0, -1, "Entry 4")
AddGadgetItem(0, -1, "Entry 3")
AddGadgetItem(0, -1, "Entry 1")
; ----- Open drop down list programmatically
HIComboBoxSetListVisible(GadgetID(0), #True)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow