ComboBoxGadget()

Syntax

Result = ComboBoxGadget(#Gadget, x, y, Width, Height [, Flags])
Description
Create a ComboBox gadget in the current GadgetList. If #PB_Any is used as '#Gadget' parameter, the new gadget number will be returned as 'Result'. #Gadget will be the number returned by EventGadget() function. Once a ComboBox is created, its list of items is empty.

You can add a 'mini help' to this gadget by using GadgetToolTip().

The following functions can be used to act on the list contents:

- AddGadgetItem(): Add an item.
- GetGadgetItemText(): Returns the gadget item text.
- CountGadgetItems(): Count the items in the current combobox.
- ClearGadgetItems(): Remove all the items.
- RemoveGadgetItem(): Remove an item.
- SetGadgetItemText(): Changes the gadget item text.

- GetGadgetState(): Get the index (starting from 0) of the current element.
- GetGadgetText(): Get the (text) content of the current element.
- SetGadgetState(): Change the selected element.
- SetGadgetText(): Set the displayed text. If the ComboBoxGadget is not editable, the text must be in the dropdown list.
- GetGadgetItemData(): Returns the value that was stored with item.
- SetGadgetItemData(): Stores a value with the item.

'Flags' are always optional and can be composed (using the '|' operator) of one of the following constants:
  #PB_ComboBox_Editable  : Makes the ComboBox editable
  #PB_ComboBox_LowerCase : All text entered in the ComboBox will be converted to lower case.
  #PB_ComboBox_UpperCase : All text entered in the ComboBox will be converted to upper case.
  #PB_ComboBox_Image     : Enable support for images in items (not supported for editable ComboBox on OSX)

Example:

  UsePNGImageDecoder()
  LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/world.png")
  
  If OpenWindow(0, 0, 0, 270, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable)
      AddGadgetItem(0, -1, "ComboBox editable...")

    ComboBoxGadget(1, 10, 40, 250, 21, #PB_ComboBox_Image)
      AddGadgetItem(1, -1, "ComboBox item with image", ImageID(0))

    ComboBoxGadget(2, 10, 70, 250, 21)
      For a = 1 To 5
        AddGadgetItem(2, -1,"ComboBox item " + Str(a))
      Next

    SetGadgetState(0, 0)
    SetGadgetState(1, 0)
    SetGadgetState(2, 2)    ; set (beginning with 0) the third item as active one
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Supported OS

All

<- CloseGadgetList() - Gadget Index - ContainerGadget() ->