ListIcons: color of selected row, can be set?

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

ListIcons: color of selected row, can be set?

Post by morosh »

Hello:
can the color of the selected row of a listicons (by SetGadgetState(), not by mouse) be set other than the default one?
The color is too fade

using W10, PB6.10b2

Thanks
PureBasic: Surprisingly simple, diabolically powerful
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: ListIcons: color of selected row, can be set?

Post by blueb »

Maybe Infratec's sample will help... :)

Code: Select all

;==================================================================
;
; Author:     Infratec    
; Date:       September 22, 2017
; 
; Question:          
;  The code below shows the centre item is slightly coloured.
;  Is there any way to get it to be the same as when selected by the mouse, i.e. Dark Blue background?          
;==================================================================

If OpenWindow(0, 100, 100, 300, 200, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   ListIconGadget(0, 5, 5, 290, 120, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
   AddGadgetColumn(0, 1, "Address", 250)
   AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
   AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
   AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
   SetActiveGadget(0) ; this is required to change the color... comment out to see.
   SetGadgetItemState(0,1,#PB_ListIcon_Selected)
      
   
   Repeat
     Event = WaitWindowEvent()
   Until Event = #PB_Event_CloseWindow
EndIf
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ListIcons: color of selected row, can be set?

Post by jacdelad »

Blueb, I think morosh means to give selected lines a different colour than Windows normally uses, not just select them.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ListIcons: color of selected row, can be set?

Post by Shardik »

morosh wrote:can the color of the selected row of a listicons (by SetGadgetState(), not by mouse) be set other than the default one?
You may try this 16 year old example from Sparkie. I have just tested it successfully on Windows 7 with PB 5.73 x86 and x64. Unfortunately I am on vacation with a 14 year old iMac and a BootCamp version which only supports Windows 7... :wink:
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: ListIcons: color of selected row, can be set?

Post by morosh »

Thank you all!!!
Finally SetGadgetItemColor did the job simply

Code: Select all

Procedure highlight2()
  Define str.s
  Static xx.u
  str=":"+LCase(GetGadgetText(52))
  SetGadgetItemColor(102,xx-1,#PB_Gadget_BackColor,$ffffff)	; reset color
  For i=1 To CountGadgetItems(102)
;   Debug i
    If FindString(GetGadgetItemText(102,i-1),str)
      Debug "Match"
      SetGadgetItemColor(102,i-1,#PB_Gadget_BackColor,$cc33ff)	; set new color
      ;      SetGadgetAttribute(102,i-1)
      xx=i
      Break
    EndIf
  Next
EndProcedure
just an extract
PureBasic: Surprisingly simple, diabolically powerful
User avatar
digital32
User
User
Posts: 30
Joined: Fri Dec 28, 2012 1:28 am

Re: ListIcons: color of selected row, can be set?

Post by digital32 »

I need to DisableGadget(GadgetName, #True) the ListIconGadget while my app updates other data to keep users from clicking on other items in the list. The SetGadgetItemColor does not seem to work when I DisableGadget(GadgetName, #False) the ListIconGadget.

Before the ListIconGadget is disable the selected row is highlighted in blue. When you disable and re-enable it the blue is gone and the row is just in a light grey.

Have tried multiple Gadget Get/Set options. Any help would be appreciated.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: ListIcons: color of selected row, can be set?

Post by boddhi »

digital32 wrote: Tue Oct 08, 2024 10:34 pm Have tried multiple Gadget Get/Set options. Any help would be appreciated.

Code: Select all

SetActiveGadget(0) ; this is required to change the color... comment out to see.
As mentionned before, you need to reactivate gadget (give the focus) with SetActiveGadget().
No focus : background color of the line is grey. With focus, background color is blue.
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...
User avatar
digital32
User
User
Posts: 30
Joined: Fri Dec 28, 2012 1:28 am

Re: ListIcons: color of selected row, can be set?

Post by digital32 »

Tried that. Here is the code. Did not set the row back to blue. Still a grey.

DisableGadget(ListIcon_Machine_List,#False) ; Allow Clicking on new row after data is loaded.
SetActiveGadget(ListIcon_Machine_List)
SetGadgetItemColor(ListIcon_Machine_List, GetGadgetState(ListIcon_Machine_List), #PB_Gadget_BackColor, $FFFF00)
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: ListIcons: color of selected row, can be set?

Post by boddhi »

Are you really sure your list has a selected item? (GetGadgetState(ListIcon_Machine_List)>=0)

Code: Select all

If OpenWindow(0, 100, 100, 400, 230, "ListIconGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 390, 90, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
  AddGadgetColumn(0, 1, "Address", 250)
  AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
  AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
  ListIconGadget(1, 5, 100, 390, 90, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
  AddGadgetColumn(1, 1, "Address", 250)
  AddGadgetItem(1, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
  AddGadgetItem(1, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
  ButtonGadget(2, 5, 200, 80, 22, "Disable")
  ButtonGadget(3, 90, 200, 80, 22, "Enable")
  SetGadgetState(0, 0)
  SetGadgetState(1, 0)
  SetActiveGadget(1)
  
  Repeat
    Evenment = WaitWindowEvent()
    Select Evenment
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 2:DisableGadget(0, #True)
          Case 3:DisableGadget(0, #False):SetActiveGadget(0)
        EndSelect
    EndSelect
  Until Evenment = #PB_Event_CloseWindow
EndIf
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...
User avatar
digital32
User
User
Posts: 30
Joined: Fri Dec 28, 2012 1:28 am

Re: ListIcons: color of selected row, can be set?

Post by digital32 »

If I comment out the DisableGadget parts it works fine. Selection stays highlighted.
Post Reply