Page 1 of 1
ListIcons: color of selected row, can be set?
Posted: Tue Mar 26, 2024 11:03 am
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
Re: ListIcons: color of selected row, can be set?
Posted: Tue Mar 26, 2024 1:55 pm
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
Re: ListIcons: color of selected row, can be set?
Posted: Tue Mar 26, 2024 1:58 pm
by jacdelad
Blueb, I think morosh means to give selected lines a different colour than Windows normally uses, not just select them.
Re: ListIcons: color of selected row, can be set?
Posted: Tue Mar 26, 2024 6:34 pm
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...

Re: ListIcons: color of selected row, can be set?
Posted: Tue Mar 26, 2024 8:25 pm
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
Re: ListIcons: color of selected row, can be set?
Posted: Tue Oct 08, 2024 10:34 pm
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.
Re: ListIcons: color of selected row, can be set?
Posted: Tue Oct 08, 2024 10:40 pm
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.
Re: ListIcons: color of selected row, can be set?
Posted: Tue Oct 08, 2024 11:06 pm
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)
Re: ListIcons: color of selected row, can be set?
Posted: Wed Oct 09, 2024 12:24 pm
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
Re: ListIcons: color of selected row, can be set?
Posted: Wed Oct 09, 2024 6:02 pm
by digital32
If I comment out the DisableGadget parts it works fine. Selection stays highlighted.