Tree Gadget Question

Just starting out? Need help? Post your questions and find answers here.
Shadow2002
User
User
Posts: 12
Joined: Mon Feb 20, 2006 7:17 am
Location: Lost in CyberSpace

Tree Gadget Question

Post 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!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Shadow2002
User
User
Posts: 12
Joined: Mon Feb 20, 2006 7:17 am
Location: Lost in CyberSpace

Post by Shadow2002 »

Oh goodness, how did I overlook that. I've been going through the help all night.

Thanks guys!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

The eventloop is by me :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Shadow2002
User
User
Posts: 12
Joined: Mon Feb 20, 2006 7:17 am
Location: Lost in CyberSpace

Post by Shadow2002 »

Nice!
Post Reply