Page 1 of 1

Tree Gadget Question

Posted: Sat Jun 02, 2007 4:58 am
by Shadow2002
Hey everyone, I got a quick question. Its something I cant seem to figure but I'm sure you guys will know. Is there a way on the tree gadget to retrieve the NAME of the child the user has selected?

For example I'll use a movie library reference....

+Action Movie
|
--- The Fifth Element
|
--- Terminator 2 <- I need the name of this if selected by the user
|
--- The Matrix

Basically how to go about getting the name of a child once the user has selected it is what is stumping me. If it was loaded in through code it wouldn't be a problem but its being loaded into the tree through a text file.

Thanks in advanced for any help!

Posted: Sat Jun 02, 2007 5:08 am
by netmaestro
Whatever is currently selected in the TreeGadget is available via GetGadgetText(#treegadget). You can use EventGadget() and EventType() to look for a #PB_EventType_Change and each time you get this, the value returned from a call to GetGadgetText() will be a new one.

Posted: Sat Jun 02, 2007 5:11 am
by ts-soft
Based on the example in the help:

Code: Select all

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  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
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Select EventType()
              Case #PB_EventType_LeftClick
                Pos = GetGadgetState(0)
                Debug GetGadgetItemText(0, Pos)
            EndSelect
          Case 1
            Select EventType()
              Case #PB_EventType_LeftClick
                Pos = GetGadgetState(1)
                Debug GetGadgetItemText(1, Pos)
            EndSelect
        EndSelect
    EndSelect
  ForEver
EndIf


Posted: Sat Jun 02, 2007 5:35 am
by Shadow2002
Oh goodness, how did I overlook that. I've been going through the help all night.

Thanks guys!

Posted: Sat Jun 02, 2007 5:49 am
by ts-soft
The eventloop is by me :wink:

Posted: Sat Jun 02, 2007 7:11 am
by Shadow2002
Nice!