SetGadgetItemData()

Syntax

SetGadgetItemData(#Gadget, Item, Value)
Description
Stores the given value with the specified gadget item. This value can later be read with the GetGadgetItemData() function. This allows to associate a custom value with the items of a gadget.

Parameters

#Gadget The gadget to use.
Item The item to use. The first item in the gadget has index 0.
Value The value to set.

Return value

None.

Remarks

The set value will remain with the item, even if the item changes its index (for example because other items were deleted).

This function works with the following gadgets:
- ComboBoxGadget()
- ListIconGadget()
- ListViewGadget()
- PanelGadget()
- TreeGadget()

Example

  ; This code uses SetGadgetItemData to store the original position
  ; of each item to later know it, even if the items index changed.
  ;
  Procedure GadgetEvent()
    item = GetGadgetState(3)
    
    Select EventGadget()
      Case 0 ; Add
        AddGadgetItem(3, item, "New Item")
        If item <> -1
          SetGadgetItemData(3, item, -1)
        Else
          SetGadgetItemData(3, CountGadgetItems(3)-1, -1)
        EndIf
        
      Case 1 ; Remove
        If item <> -1
          RemoveGadgetItem(3, item)
        EndIf
        
      Case 2 ; Test
        If item <> -1
          value = GetGadgetItemData(3, item)
          If value = -1
            Debug "Its a new item"
          Else
            Debug "It was item number " + value
          EndIf
        EndIf
        
    EndSelect
  EndProcedure
  
  If OpenWindow(0, 0, 0, 280, 250, "SetGadgetItemData", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0,  10, 10, 80, 20, "Add")
    ButtonGadget(1, 100, 10, 80, 20, "Remove")
    ButtonGadget(2, 190, 10, 80, 20, "Test")
    ListViewGadget(3, 10, 40, 260, 200)
    For i = 0 To 10
      AddGadgetItem(3, i, "Old Item "+Str(i))
      SetGadgetItemData(3, i, i)
    Next i
    
    BindEvent(#PB_Event_Gadget, @GadgetEvent())
  EndIf

See Also

GetGadgetItemData(), GetGadgetData(), SetGadgetData()

Supported OS

All

<- SetGadgetItemAttribute() - Gadget Index - SetGadgetItemImage() ->