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
issue SetGadgetItemColor
Re: issue SetGadgetItemColor
Welcome to the english PureBasic forum!
By the way: you should use the button "</>" above the text input field for posting PureBasic code!
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: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?
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
Re: issue SetGadgetItemColor
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
