Main Menu

News:

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

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

Shoutbox

GfK

Today at 17:45:33
My mop and bucket was £30. 🤨 It's a Vileda one and you stick it in the bucket and press a pedal with your foot and it spins round and dries the mop out AND IT'S BRILLIANT! 👌

Dabzy

Today at 16:19:35
Oh, I can give you a tip right now, no need to wait... Ahem... Pay someone a fiver to do it, even the bucket was a chew! :D ;)

Jackdaw

Today at 16:04:05
Well if the occasion should ever arise, where I need to gift wrap a mop and bucket. I know where to get tips from ;)

Dabzy

Today at 14:24:38
Has anyone ever tried to wrap up a mop? Never again! :D

Dabzy

Today at 12:17:43
Lol, not the ones from Poundland! :D Anyway, I've got a nice box of chocolates and a Prosecco to go in the bucket! ;)

Jackdaw

Today at 11:18:06
@Dabzy I think they will appreciate it. Have you seen how much it can cost for a good mop and bucket set in this day and age.  I can buy a bottle of Blonde chocolate cream liqueur for less at ASDA.

Dabzy

Today at 10:47:41
Well, I'm off out to buy a 60th birthday pressie... A mam of one of me mates... Gonna get her a mop and bucket, and wrap it up, even wrap the noodly mop bits individually... All in Christmas wrapping paper... Should go down well! :D

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!

Members
Stats
  • Total Posts: 1,826
  • Total Topics: 226
  • Online today: 23
  • Online ever: 232 (Oct 08, 2025, 09:18 AM)
Users Online
  • Users: 0
  • Guests: 13
  • Total: 13
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