Getting informations from a treeview

BlitzMax Forums/BlitzMax GUI Programming/Getting informations from a treeview

Do you mean find out nodes without getting an event? You need to loop through a gadget's kid field. I rustled up the following example (originating from the CreateTreeView sample in the docs). It should present the nodes in a text format in the message box...

' createtreeview.bmx

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,240,240,Null,WINDOW_TITLEBAR)
Local treeview:TGadget=CreateTreeView(0,0,200,200,window)

SetGadgetLayout treeview,2,2,2,2

Local root:TGadget=TreeViewRoot(treeview)

Local help:TGadget=AddTreeViewNode("Help",root)
AddTreeViewNode "topic 1",help
AddTreeViewNode "topic 2",help
AddTreeViewNode "topic 3",help

Local projects:TGadget=AddTreeViewNode("Projects",root)
AddTreeViewNode("project 1",projects)
AddTreeViewNode("Another level",AddTreeViewNode("project 2",projects))
AddTreeViewNode("project 3 is a big waste of time",projects)

Notify ConvertTreeviewToString$(treeview)

While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend


Function ConvertTreeviewToString$(gadTreeview:TGadget, recurse:Int = 0)

	Local tmpOutputString:String
	
	Assert gadTreeview <> Null,"The gadget passed referred to a Null object."
	
		If recurse = 0 Then gadTreeview = TreeViewRoot(gadTreeview)
		
		For Local tmpNodeChildren:TGadget = EachIn gadTreeview.kids
		
			For Local tmpLoop% = 1 To recurse;tmpOutputString:+">";Next
			tmpOutputString:+GadgetText(tmpNodeChildren)+"~r~n"
			If tmpNodeChildren.kids.Count() Then tmpOutputString:+ConvertTreeViewToString$(tmpNodeChildren,recurse+1)
		
		Next 
	
	Return tmpOutputString

EndFunction