ListIconGadget and SetGadgetItemColor

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

ListIconGadget and SetGadgetItemColor

Post 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
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: ListIconGadget and SetGadgetItemColor

Post 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
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: ListIconGadget and SetGadgetItemColor

Post by boddhi »

Finally, I searched and found this post
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
jak64
Enthusiast
Enthusiast
Posts: 639
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: ListIconGadget and SetGadgetItemColor

Post 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
Post Reply