Main Menu

News:

SyntaxBoom, now with pwetty syntax highlighted code boxes! \o/ 

https://www.syntaxboom.com/forum/index.php?topic=96

Shoutbox

Dabzy

2025-10-17, 17:36:22
Well, just have to keep an eyes, even though they said they sorted it like

Jackdaw

2025-10-17, 17:22:26
When I saw it. It was in the very early hours when normal people are fast asleep. Lasted for around half an hour before back to normal.

Dabzy

2025-10-17, 15:02:27
First time I seen it, having me cuppa at work and had a browse... Saw it and I was like "WTF is that!?!", so got on the blower!

Baggey

2025-10-17, 11:22:52
Oh goody. Was getting withdraw symptons!

Jackdaw

2025-10-17, 10:38:44
I saw that the other week, and forgot to query it. Redirects to sedo.parking.

Dabzy

2025-10-17, 10:33:24
Seems we lost the site for a bit there, sorted, basically htaccess went a bit screwy and it was diverting to one of them stupid default search pages... Been on to ionos the host provider and they fixered it! \o/ Had meself a bit of a sweat on there!  ;D

Jackdaw

2025-10-16, 20:00:40
Going to have to try bourbon and beans. That should be an explosive combination.

Baggey

2025-10-16, 13:15:42
I sometimes mix a chicken vindaloo and a Tika Masala together. Awesome  :P

Dabzy

2025-10-16, 05:49:34
And doing the act was the realisation I went for an indian when out... 20mins I was in the thunderbox waiting for me back chaff to cool down!

Dabzy

2025-10-16, 05:48:11
When I was on my "Year On The Blur", aka drinking after getting divorced, I was minging one night, couldnt remember getting home. Anyway, next day, went to work, and needed a poo...

Members
Stats
  • Total Posts: 1,816
  • Total Topics: 226
  • Online today: 29
  • Online ever: 232 (Oct 08, 2025, 09:18 AM)
Users Online
  • Users: 0
  • Guests: 5
  • Total: 5
Welcome to SyntaxBoom. Please login or sign up.

Recent

How to get MaxGui Treeview Node Index

Started by Chalky, Jun 15, 2025, 11:21 PM

Previous topic - Next topic

Chalky

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?

Dabzy

#1
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
Intel i7-13620H, nVidia GerForce RTX 4060 Laptop GPU (8GB GDDR6), 16GB LPDDR5X, 1TB SSD, Windows 11 x64 piss flap of an OS!

Chalky

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

_PJ_

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