Restored from previous forum. Originally posted by Justin.
I have a listicon with 3 columns and some items, when i try to change the text of an item in any colummn it does not work, changing the item state does not work either.
I have build a whole app thinking that this was possible, it is just me or is a bug?
I'm using PB 3.20, please answer.
SetGadgetItemText / SetGadgetItemState don't work?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
Now how can anyone help when you post no code??
This works fine for me:
This little example selects the 6th item when you press Select
and changes the value of 6th item, 2nd column when you press Change.
(remember... lists start at 0 so 6th item is 5 (6-1)
Now how can anyone help when you post no code??
This works fine for me:
Code: Select all
hWnd=OpenWindow(0,10,10,400,300,#PB_Window_SystemMenu,"Test")
If CreateGadgetList(hWnd)=0 Or hWnd=0:End:EndIf
ListIconGadget(0,10,10,300,200,"Index",50,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(0,1,"Name",80)
AddGadgetColumn(0,2,"Phone",80)
ButtonGadget(1,240,270,50,20,"Select")
ButtonGadget(2,300,270,50,20,"Change")
For tmp=1 To 9
AddGadgetItem(0,-1,Str(tmp)+Chr(10)+"Test"+Str(tmp)+Chr(10)+"555"+Str(tmp))
Next
Repeat
eventid=WaitWindowEvent()
If eventid=#PB_EventGadget
If EventGadgetID()=1
SetGadgetState(0,5)
EndIf
If EventGadgetID()=2
SetGadgetItemText(0,5,"NEW VALUE",1)
EndIf
EndIf
Until eventid=#PB_EventCloseWindow
End
and changes the value of 6th item, 2nd column when you press Change.
(remember... lists start at 0 so 6th item is 5 (6-1)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Justin.
Thank you, that code helped me to find the problem.
I was breaking the message loop after changing the text, and it seems that this is not allowed in PB.
This code changes the text of the selected items and then breaks the message loop, the text does not change, i did not know that behaviour.
Removing the break works.
hWnd=OpenWindow(0,10,10,400,300,#PB_Window_SystemMenu,"Test")
If CreateGadgetList(hWnd)=0 Or hWnd=0:End:EndIf
ListIconGadget(0,10,10,300,200,"Index",50,#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect)
AddGadgetColumn(0,1,"Name",80)
AddGadgetColumn(0,2,"Phone",80)
ButtonGadget(1,240,270,50,20,"Select")
ButtonGadget(2,300,270,50,20,"Change")
For tmp=1 To 9
AddGadgetItem(0,-1,Str(tmp)+Chr(10)+"Test"+Str(tmp)+Chr(10)+"555"+Str(tmp))
Next
Repeat
eventid=WaitWindowEvent()
If eventid=#PB_EventGadget
If EventGadgetID()=1
SetGadgetState(0,5)
SetGadgetState(0,6)
EndIf
If EventGadgetID()=2
For index=0 To 8
If GetGadgetItemState(0, index)=2
SetGadgetItemText(0,index,"NEW VALUE",1)
EndIf
Next
break=#true
EndIf
EndIf
Until eventid=#PB_EventCloseWindow Or break
Delay(5000)
Thank you, that code helped me to find the problem.
I was breaking the message loop after changing the text, and it seems that this is not allowed in PB.
This code changes the text of the selected items and then breaks the message loop, the text does not change, i did not know that behaviour.
Removing the break works.
hWnd=OpenWindow(0,10,10,400,300,#PB_Window_SystemMenu,"Test")
If CreateGadgetList(hWnd)=0 Or hWnd=0:End:EndIf
ListIconGadget(0,10,10,300,200,"Index",50,#PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect)
AddGadgetColumn(0,1,"Name",80)
AddGadgetColumn(0,2,"Phone",80)
ButtonGadget(1,240,270,50,20,"Select")
ButtonGadget(2,300,270,50,20,"Change")
For tmp=1 To 9
AddGadgetItem(0,-1,Str(tmp)+Chr(10)+"Test"+Str(tmp)+Chr(10)+"555"+Str(tmp))
Next
Repeat
eventid=WaitWindowEvent()
If eventid=#PB_EventGadget
If EventGadgetID()=1
SetGadgetState(0,5)
SetGadgetState(0,6)
EndIf
If EventGadgetID()=2
For index=0 To 8
If GetGadgetItemState(0, index)=2
SetGadgetItemText(0,index,"NEW VALUE",1)
EndIf
Next
break=#true
EndIf
EndIf
Until eventid=#PB_EventCloseWindow Or break
Delay(5000)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Paul.
If you want the window to update after you have left your loop you need to do this:
If you want the window to update after you have left your loop you need to do this:
Code: Select all
If EventGadgetID()=2
For index=0 To 8
If GetGadgetItemState(0, index)=2
SetGadgetItemText(0,index,"NEW VALUE",1)
EndIf
Next
While WindowEvent():Wend ; <--- this forces an update
break=#true
EndIf
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm