Page 1 of 1

ListIconGadget with HyperLinkGadget

Posted: Sun Feb 15, 2026 8:05 am
by ZX80
Hello all.

Sorry if this topic has already been raised, I couldn't find it.
Problem: I have a ListIconGadget and I would like to place a link in one of the columns (the last one) so that when clicked, an event is generated. It doesn't necessarily have to be HyperLinkGadget(). The main thing is to catch the click event on the text.

Thanks in advance !

Re: ListIconGadget with HyperLinkGadget

Posted: Sun Feb 15, 2026 8:31 am
by Jacobus
Hello,
Example to retrieve a specific element from the ListiconGadget() and do whatever you want with it.

Code: Select all

;- Main loop
  Repeat
    Select WaitWindowEvent()
         ;-Event Gadgets  
      Case #PB_Event_Gadget
        Select EventGadget()
            
          Case #LISTICON 
            Pos = GetGadgetState(#LISTICON)
            If Pos >= 0
              If EventType() = #PB_EventType_RightClick
                If GetGadgetItemState(#LISTICON, Pos) & #PB_ListIcon_Selected
                  NumColumn = 0 ; 1 or 2 or 3..... or the number of the last column
                                ; Here's the action to perform. 
                                ; In this example, we retrieve the element To modify it.
                  SelectItem$ = GetGadgetItemText(#LISTICON, Pos, NumColumn)
                  NewData$ = InputRequester("Modify", "Element to be modified:", SelectItem$ )
                  If NewData$
                    SetGadgetItemText(#LISTICON, Pos, NewData$, NumColumn)
                  EndIf 
                EndIf
              EndIf
            EndIf 
        EndSelect 
        
        ;-Event Close     
      Case #PB_Event_CloseWindow
        
        Break
        
    EndSelect   
  ForEver 
Another example of launching an external program
replaces the previous action section with this one

Code: Select all

SelectItem$ = GetGadgetItemText(#LISTICON, Pos, NumColumn) 
                  If SelectItem$ <>""
                    RunProgram(SelectItem$ + ".txt") ; if it's a text file
                  EndIf

Re: ListIconGadget with HyperLinkGadget

Posted: Sun Feb 15, 2026 10:41 am
by Jacobus
I know it's not exactly what you're looking for, but it's simple and it gets the job done. A more complete example...

Code: Select all

Enumeration
  #WIN
  #TEXTCOLUMN
  #Opt_0
  #Opt_1
  #Opt_2
  #Opt_3
  #Opt_4
  #Opt_5
  #Opt_6
  #LISTICON
  #TEXTCOUNTITEMS
EndEnumeration

Procedure.i SelectOption()
   
  If GetGadgetState(#Opt_0) = 1
    NumColumn = 0
  ElseIf GetGadgetState(#Opt_1) = 1
    NumColumn = 1
  ElseIf GetGadgetState(#Opt_2) = 1
    NumColumn = 2
  ElseIf GetGadgetState(#Opt_3) = 1
    NumColumn = 3
  ElseIf GetGadgetState(#Opt_4) = 1
    NumColumn = 4
  ElseIf GetGadgetState(#Opt_5) = 1
    NumColumn = 5
  ElseIf GetGadgetState(#Opt_6) = 1
    NumColumn = 6
  EndIf 
  ProcedureReturn NumColumn          
  
EndProcedure


If OpenWindow(#WIN, 0, 0, 800, 600, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget)
  
  TextGadget(#TEXTCOLUMN, 5, 5, 120, 17, "Select the column: ")
  OptionGadget(#Opt_0, 130, 5, 80, 17, "Col n° 0")
  OptionGadget(#Opt_1, 210, 5, 80, 17, "Col n° 1")
  OptionGadget(#Opt_2, 290, 5, 80, 17, "Col n° 2")
  OptionGadget(#Opt_3, 370, 5, 80, 17, "Col n° 3")
  OptionGadget(#Opt_4, 450, 5, 80, 17, "Col n° 4")
  OptionGadget(#Opt_5, 530, 5, 80, 17, "Col n° 5")
  OptionGadget(#Opt_6, 610, 5, 80, 17, "Col n° 6") : SetGadgetState(#Opt_6, 1)
               
  ListIconGadget(#LISTICON, 5, 30, 790, 540, "Col n° 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
  For x = 1 To 6
    AddGadgetColumn(#LISTICON, x, "Col n° " + x, 100)
  Next 
  
  For a = 0 To 500
    AddGadgetItem(#LISTICON, -1, Str(a+1) +Chr(10)+ Str(a+2) +Chr(10)+ Str(a+3) +Chr(10)+ Str(a+4) +Chr(10)+ Str(a+5) +Chr(10)+ Str(a+6) +Chr(10)+ Str(a+7) )
    SetGadgetItemColor(#LISTICON, -1, #PB_Gadget_FrontColor, RGB(68, 98, 201), 6)
    a+1
  Next 
       
  TextGadget(#TEXTCOUNTITEMS, 5, 576, 790, 17, "Number of items in the list: " + Str(CountGadgetItems(#LISTICON)))
  
 ;- Main loop
  Repeat
    Select WaitWindowEvent()
        ;-Event Gadgets  
    
      Case #PB_Event_Gadget
        Select EventGadget()
            
          Case #LISTICON 
            Pos = GetGadgetState(#LISTICON)
            If Pos >= 0
              If EventType() = #PB_EventType_RightClick
                  
                If GetGadgetItemState(#LISTICON, Pos) & #PB_ListIcon_Selected
                  NumColumn = SelectOption() ; 1 or 2 or 3..... or the number of the last column
                                ; Here's the action to perform. 
                                ; In this example, we retrieve the element To modify it.
                  SelectItem$  = GetGadgetItemText(#LISTICON, Pos, NumColumn)
                  ColumnTitle$ = GetGadgetItemText(#LISTICON, -1, NumColumn)
                  NewData$ = InputRequester("Modify", "Element in column "+ColumnTitle$+" To be modified:", SelectItem$ )
                  If NewData$
                    SetGadgetItemText(#LISTICON, Pos, NewData$, NumColumn)
                  EndIf 
                  
;                   ; Another example of launching an external program
;                   SelectItem$ = GetGadgetItemText(#LISTICON, Pos, NumColumn) 
;                   If SelectItem$ <>""
;                     RunProgram(SelectItem$ + ".txt") ; if it's a text file
;                   EndIf 
                  
                  
                EndIf
              EndIf
            EndIf 
        EndSelect 
        
        ;-Event Close     
      Case #PB_Event_CloseWindow
        
        Break
        
    EndSelect   
  ForEver 
EndIf 

Re: ListIconGadget with HyperLinkGadget

Posted: Sun Feb 15, 2026 7:29 pm
by Jacobus
I found this code from RASHAD which is exactly what you're looking for
viewtopic.php?t=55780

Re: ListIconGadget with HyperLinkGadget

Posted: Sun Feb 15, 2026 8:22 pm
by ZX80
Jacobus, thank you very much. This is what I needed ! Excellent !