Page 1 of 1

ListIconGadget and SetGadgetItemColor

Posted: Tue Jul 02, 2024 7:56 pm
by jak64
Good morning,
In this little example, when I right click on a line, I want the background to turn red immediately.

However, the color remains blue and it is only when I select another line that the background becomes red.

Is there a trick to make the background turn red immediately when I right click on it?

thank you

Code: Select all

OpenWindow(0, 0, 0, 600, 400, "Test")
ListIconGadget(0, 0, 0, 400, 200, "Exemple", 150, #PB_ListIcon_FullRowSelect)
AddGadgetItem (0,-1,"aaaaaa")
AddGadgetItem (0,-1,"bbbbbb")
AddGadgetItem (0,-1,"cccccc")

Repeat
  Event = WaitWindowEvent()
     Select Event
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 0
             Select EventType()
               Case #PB_EventType_RightClick
                 r = GetGadgetState(0)
                 If  r > -1
                  SetGadgetItemColor(0, r , #PB_Gadget_BackColor , #Red, #PB_All) 
                EndIf    
            EndSelect
        EndSelect
      EndSelect
Until Event = #PB_Event_CloseWindow

Re: ListIconGadget and SetGadgetItemColor

Posted: Tue Jul 02, 2024 8:33 pm
by boddhi
Salut Jak
jak64 wrote: Is there a trick to make the background turn red immediately when I right click on it?
Selection colors are under operating system control, not PB's. That's why you can't alter them using PB's instructions.

Code: Select all

OpenWindow(0, 0, 0, 600, 400, "Test")
ListIconGadget(0, 0, 0, 400, 200, "Exemple", 150)
AddGadgetColumn(0,1,"Column 2",150)
AddGadgetItem (0,-1,"aaaaaa"+Chr(10)+"bbbbbb")
Repeat
  Event = WaitWindowEvent()
     Select Event
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 0
             Select EventType()
               Case #PB_EventType_RightClick
                 r = GetGadgetState(0)
                 If  r > -1
                  SetGadgetItemColor(0, r , #PB_Gadget_BackColor , #Red, #PB_All) 
                  SetGadgetItemColor(0, r , #PB_Gadget_FrontColor , #Blue,#PB_All) 
                EndIf    
            EndSelect
        EndSelect
      EndSelect
Until Event = #PB_Event_CloseWindow
And I'm not sure you can change this only for your gadget...maybe with API, I don't search...
If Rashad, the great specialist, pass through here... :D

Re: ListIconGadget and SetGadgetItemColor

Posted: Tue Jul 02, 2024 8:50 pm
by boddhi
Finally, I searched and found this post

Re: ListIconGadget and SetGadgetItemColor

Posted: Tue Jul 02, 2024 8:53 pm
by jak64
Actually, I found, just add:
setGadgetState(0, -1)

Code: Select all

OpenWindow(0, 0, 0, 600, 400, "Test")
ListIconGadget(0, 0, 0, 400, 200, "Exemple", 150, #PB_ListIcon_FullRowSelect)
AddGadgetItem (0,-1,"aaaaaa")
AddGadgetItem (0,-1,"bbbbbb")
AddGadgetItem (0,-1,"cccccc")

Repeat
  Event = WaitWindowEvent()
     Select Event
       Case #PB_Event_Gadget
         Select EventGadget()
           Case 0
             Select EventType()
               Case #PB_EventType_RightClick
                 r = GetGadgetState(0)
                 If  r > -1
                   SetGadgetItemColor(0, r , #PB_Gadget_BackColor , #Red, #PB_All)
                   SetGadgetState(0,-1)
                EndIf    
            EndSelect
        EndSelect
      EndSelect
Until Event = #PB_Event_CloseWindow