I am attempting to create a directory tree using a Treeview gadget. The tree is refreshed whenever the user selects a drive from a combobox - at which point I rebuild the tree starting at the drive but without recursion (as it would take forever). If the user then double-clicks a node, I need to read the selected directory and insert the entries immediately after that node. I thought it would be a simple case of using InsertTreeViewNode - but that requires a node index which appears to be inaccessible via any native MaxGui commands. Does anyone know where the index is stored and how I can retrieve it?
Tree nodes are notoriously pap in their design, never mind MaxGUI's.
You could use a type that holds the nodes AND id's (the views indices), and self manage them, this would mean sorting after every insert, but off the top of my head, that's how I would approach it.
I have noticed there is an "extra" that takes an object, you could there for give each node a unique key when looking for the nodes index.
Whichever way... A jiggle here and there maybe be required.
This is why I use wxMax, much better then MaxGUI!
Dabz
Thank you Dabz - as per your suggestion I used the Extra() part of each Node to store the index (and full path). All sorted! :D
I hope I am understanding your issue correctly. Apologies if I've confused things.
The TGADGET objects of children of ROOTs and NODES are found within the "kids[]" array
Setting an index of -1 will always insert at the end of the kids array - but you already know the currently selected node from SelectedTreeViewNode
I don't know how many sub-nodes you may have per node, but would it be viable to iterate through the kids[] array until you find a match for the current selection and then just insert at this element +1
Alternatively, I believe adding at index 0 will force it to the top and push all other entries down the list.
Import MaxGUI.Drivers ' For Windows UI
Import MaxGUI.ProxyGadgets ' Add Splitter and Tabber
Global WIN:TGadget=CreateWindow("Test",0,0,1024,768)
Global TREEVIEW_Gadget:TGadget=CreateTreeView(0,0,1024,768,WIN)
Global Root:TGadget=TreeViewRoot(TREEVIEW_Gadget)
For Local Branches:Int=1 To 5
Local Branch:TGadget=AddTreeViewNode("Main Branch "+String(Branches),Root)
For Local Iter:Int=1 To 5
AddTreeViewNode("Sub-Branch "+Branches+":"+String(Iter),Branch)
Next
Next
While WaitEvent()
Print CurrentEvent.ToString()
Select EventID()
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE;End
Case EVENT_GADGETACTION
Select GadgetClass(TGadget(EventSource()))
Case GADGET_TREEVIEW
Local Selected:TGadget=(SelectedTreeViewNode(TGadget(EventSource())))
DebugLog("Selected: "+GadgetText(Selected))
Local Parent:TGadget=GadgetGroup(Selected)
Local n:Int
For Local Iter:Tgadget=EachIn Parent.kids[]
If (Iter=Selected) Then Exit
n:+1
Next
Notify("Current Index of Selected item is: "+GadgetText(Parent)+" ["+n+"]")
Case GADGET_NODE
' Not sure if this is captured
EndSelect
End Select
Wend