Voici le code permettant de le faire :
Code : Tout sélectionner
EnableExplicit
Enumeration
#SEARCH_WIN
#SEARCH_COMBO
#SEARCH_BUTTON_OK
EndEnumeration
Procedure.i CheckAddItem(__Item.s, List __lKeywords.s())
Protected.i _posItem = 0, _index = 0, _Found = #False, _indexInList = ListSize(__lKeywords())
If _indexInList > 0
ForEach __lKeywords()
If __lKeywords() = __Item
_Found = #True
Break
EndIf
_posItem + 1
Next
If Not _Found
AddElement(__lKeywords())
__lKeywords() = __Item
EndIf
Else
; First time use, need to add
AddElement(__lKeywords())
__lKeywords() = __Item
EndIf
;Populate the combobox
ClearGadgetItems(#SEARCH_COMBO)
;Get the last 10 max keywords in the combobox
ResetList(__lKeywords())
For _index = 1 To 10
If NextElement(__lKeywords())
AddGadgetItem(#SEARCH_COMBO, -1, __lKeywords())
EndIf
Next
; Set the item in the combobox if found
If _Found : Debug _posItem : SetGadgetState(#SEARCH_COMBO, _posItem) : EndIf
ProcedureReturn _posItem
EndProcedure
Procedure SearchDB()
Protected.i _Quit = #False, _PosItem = 0
Protected.s NewList _lKeywords()
If OpenWindow(#SEARCH_WIN, 0, 0, 270, 180, "Adding unique value inside ComboBox", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(#SEARCH_COMBO, 10, 10, 220, 21, #PB_ComboBox_Editable|#PB_ComboBox_LowerCase)
AddGadgetItem(#SEARCH_COMBO, -1, "")
ButtonGadget(#SEARCH_BUTTON_OK, 230, 9, 30, 23, "Ok")
SetGadgetState(#SEARCH_COMBO, 0)
SetActiveGadget(#SEARCH_COMBO)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
_Quit = #True
Case #WM_KEYDOWN
Select EventwParam()
Case #VK_RETURN
_PosItem = CheckAddItem(GetGadgetText(#SEARCH_COMBO), _lKeywords())
SetActiveGadget(#SEARCH_COMBO)
Debug GetGadgetItemText(#SEARCH_COMBO, _PosItem)
Case #VK_ESCAPE
_Quit = #True
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #SEARCH_BUTTON_OK
_PosItem = CheckAddItem(GetGadgetText(#SEARCH_COMBO), _lKeywords())
SetActiveGadget(#SEARCH_COMBO)
Debug GetGadgetItemText(#SEARCH_COMBO, _PosItem)
EndSelect
EndSelect
Until _Quit
EndIf
EndProcedure
SearchDB()