issue SetGadgetItemColor

Just starting out? Need help? Post your questions and find answers here.
huubkeb
New User
New User
Posts: 2
Joined: Sun Jan 12, 2025 9:18 am

issue SetGadgetItemColor

Post by huubkeb »

Hello guys,
Tried to give each row from listicongadget different colour.
It's working with for next, but not with while wend. A bug?

here the code;

If OpenWindow(0, 500, 0, 500, 300, " kleur while wend", #PB_Window_SystemMenu)
CreateStatusBar(0, WindowID(0))
ListIconGadget(0, 10, 10, 480, 255, "kolom 0", 200, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_AlwaysShowSelection)
a=0
AddGadgetColumn(0, 1, "kolom 1", 200)
AddGadgetColumn(0, 2, "kolom 2", 200)
While a<9
a=a+1

addtext$ = "kolom 0 item # " + Str(a) + Chr(10) + "kolom 1 item # " + Str(a) + Chr(10) + "kolom 2 item # " + Str(a)
AddGadgetItem(0,-1, addtext$)
If a % 2
SetGadgetItemColor(0,a, #PB_Gadget_BackColor,$ACFEFD)
SetGadgetItemColor(0,a, #PB_Gadget_FrontColor,$FF0806)
Else
SetGadgetItemColor(0,a, #PB_Gadget_BackColor,$FFFFFF)
SetGadgetItemColor(0,a, #PB_Gadget_FrontColor,$0)
EndIf
Wend



If OpenWindow(1, 0, 0, 500, 300, "kleur for next", #PB_Window_SystemMenu)
CreateStatusBar(0, WindowID(1))
ListIconGadget(1, 10, 10, 480, 255, "kolom 0", 200, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_AlwaysShowSelection)

AddGadgetColumn(1, 1, "kolom 1", 200)
AddGadgetColumn(1, 2, "kolom 2", 200)
For a=0 To 9
addtext$ = "kolom 0 item # " + Str(a) + Chr(10) + "kolom 1 item # " + Str(a) + Chr(10) + "kolom 2 item # " + Str(a)
AddGadgetItem(1,-1, addtext$)
If a % 2
SetGadgetItemColor(1,a, #PB_Gadget_BackColor,$ACFEFD)
SetGadgetItemColor(1,a, #PB_Gadget_FrontColor,$FF0806)
Else
SetGadgetItemColor(1,a, #PB_Gadget_BackColor,$FFFFFF)
SetGadgetItemColor(1,a, #PB_Gadget_FrontColor,$0)
EndIf
Next


Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndIf
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndIf
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: issue SetGadgetItemColor

Post by Shardik »

Welcome to the english PureBasic forum!
huubkeb wrote: Sun Jan 12, 2025 9:25 am Tried to give each row from listicongadget different colour.
It's working with for next, but not with while wend. A bug?
In your While..Wend example you are incrementing variable a before creating addtext$ and setting the color. You have to increment a at the end of the While..Wend loop and it will work like a charm:

Code: Select all

If OpenWindow(0, 500, 0, 500, 300, " kleur while wend", #PB_Window_SystemMenu)
  CreateStatusBar(0, WindowID(0))
  ListIconGadget(0, 10, 10, 480, 255, "kolom 0", 200, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_AlwaysShowSelection)
  a=0
  AddGadgetColumn(0, 1, "kolom 1", 200)
  AddGadgetColumn(0, 2, "kolom 2", 200)
  While a<9
    addtext$ = "kolom 0 item # " + Str(a) + Chr(10) + "kolom 1 item # " + Str(a) + Chr(10) + "kolom 2 item # " + Str(a)
    AddGadgetItem(0,-1, addtext$)
    If a % 2
      SetGadgetItemColor(0,a, #PB_Gadget_BackColor,$ACFEFD)
      SetGadgetItemColor(0,a, #PB_Gadget_FrontColor,$FF0806)
    Else
      SetGadgetItemColor(0,a, #PB_Gadget_BackColor,$FFFFFF)
      SetGadgetItemColor(0,a, #PB_Gadget_FrontColor,$0)
    EndIf

    a=a+1
  Wend
  
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
EndIf
By the way: you should use the button "</>" above the text input field for posting PureBasic code!
huubkeb
New User
New User
Posts: 2
Joined: Sun Jan 12, 2025 9:18 am

Re: issue SetGadgetItemColor

Post by huubkeb »

:D Thnx
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: issue SetGadgetItemColor

Post by Demivec »

The while loop's control values are still wrong.

Code: Select all

;This For/Next loop . . .
For a = 0 To 9
  ; // loop statements //
 Next
 
 ;is the same as this While/Wend loop.
 a = 0
 While a <= 9
   ; // loop statements //
   a + 1
Wend
Post Reply