Getting informations from a treeview

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

I really love the TreeView gadget. But it's also very tricky to handle. For my program I'd like to store the informations from the treeview. Is this even possible?



You can see the treeview to the right. I'd like to store this tree into the database (using SQLite).


Probably I will use a different method: I will store the informations temporarily into the memory and then (when I choose "Save") I will copy the db infos to the project file.
Loading will be no problem.


But is it possible to get informations from a treeview without clicking it, etc.. ?


Regards,
Michael

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


That's what I was looking for.
Thanks man!