I am learning to use the tree gadget. I modified the example of the help file and want to get the item whenever its checkbox is checked. In below code the message appear twice whenever I tick a item's checkbox. Please advise.
Working in win 10 pro PB 6.11
Thanks
Allen
Code: Select all
If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, 160, 160) ; TreeGadget standard
TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes | #PB_Tree_NoLines) ; TreeGadget with Checkboxes + NoLines
For ID = 0 To 1
For a = 0 To 10
AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use
AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0) ; ImageID(x) as 4th parameter
AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1) ; These are on the 1st sublevel
AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
Next
Next
Repeat :
Event=WaitWindowEvent()
If Event= #PB_Event_CloseWindow
End
EndIf
If Event= #PB_Event_Gadget
Select EventGadget()
Case 1
SelectedItem=GetGadgetState(1)
If SelectedItem>-1
ItemState=GetGadgetItemState(1,SelectedItem)
If ItemState & #PB_Tree_Checked
MessageRequester(" Selected Item Info ",Str(SelectedItem)+" "+GetGadgetItemText(1,SelectedItem))
EndIf
EndIf
EndSelect
EndIf
ForEver
EndIf