[MaxGUI] How to swap TreeView-Nodes

BlitzMax Forums/BlitzMax Beginners Area/[MaxGUI] How to swap TreeView-Nodes

This treeview really gives me a hard time. I "just" want to swap two nodes inside a treeview. I thought of removing node N1 and inserting it before/after N2. Sounds like a good idea, but my next problem: How to get the index of node (InsertNode needs this as parameter)?

If there were methods to work nicely with treeviews...

It could be the bloody hot weather, but my brain feels cooked.

like this? node_A and node_B text are swapped?

Strict 

Local window:TGadget=CreateWindow("My Window",50,50,240,240)
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
Local node_A:TGadget = AddTreeViewNode("topic 3",help)

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

ModifyTreeViewNode node_A,"project 3 is a big waste of time"
ModifyTreeViewNode node_B,"topic 3"

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



Here is more complex one, (but maybe easier to follow ;)
It Swaps currently the whole Node which is given to the Swap Function in this case the RootNode.

SuperStrict

Local Main:TGadget = CreateWindow("Main" , 20 , 20 , 400 , 400)
Local Tree:TGadget = CreateTreeView(10 , 10 , 360 , 250 , MAin)
Local SwapButton:TGadget = CreateButton("SWAP" , 160 , 260 , 40 , 40 , Main)
Local Root:TGadget = TreeViewRoot(Tree)
For Local Index:Int = 0 To 99
	AddTreeViewNode(Index , Root)
Next



While WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_GADGETACTION
			Select EventSource() 
				Case SwapButton
					Swap(Root)
					Print "Swapped"
				'	RedrawGadget(Tree)
			End Select
		
	End Select
Wend

Function Swap(Node:TGadget)
	ReverseList(Node.Kids)
	Local List:Object[] = Node.Kids.toArray()	
	For Local TempNOde:TGadget = EachIn Node.Kids
		TempNode.Free()
	Next
	For Local TempNode:TGadget = EachIn List
		AddTreeViewNode(TempNode.Name,Node)
	Next
	
End Function



Thanks klepto, this helps!