Notifications
Clear all

[Closed] Adding to a TreeView ActiveX Control

I’m having one heck of a time adding objects to a tree view! I’ve narrowed the problem down to the “add” function because I stripped that function from my script and it operates perfectly. Of course, an almost empty tree-view isn’t very useful.

My question is; how can I assign things like a node’s parent? I have an array of structs that hold all the important data (uniqueID, Parent’s ID, names, parameters, etc)- but I can’t seem to translate that into a treeView.

Any thoughts on how to set a node’s parent after it’s created?

Thx!

3 Replies

Here’s something of a construction function I’m trying to use; but it just won’t do it. It’ll compile though, so I know I’m close.

Here’s what it should do:
For every struct in the array it will take down the object’s Unique ID.
Then, for every struct in the array, if the “parent” id matches the unique ID, the function will add a child node and recurse.


 fn constructTree tv cArray thisNode=
 (
 	for i = 1 to cArray.count do
 	(
 		thisID = (cArray[i].uniqueID as number)
 		for j = 1 to cArray.count do
 		(
 			if j == i do continue;
 			if cArray[j].parent == thisID
 			do 
 			(
 				newNode = tv.Nodes.add thisNode.index 4 "" cArray[j].ClassName 0
 				constructTree tv cArray thisNode
 			)
 		)
 	)
 )
 

It takes a monumental amount of critical thinking, but you can pretty much blast your way through this problem.

My solution came around when I used two functions in tandem:

The first would set up any base objects that are not parented to anything. Then, whenever any of these were constructed, I could call the second function.

The second function would be a recursive process that would check the other objects in the array to see if thier <object>.parentID was the same as the <rootObject>.uniqueID. That way, if they matched, the function would make the subordinate object a child to the parent. Then, because it’s recursive, it would run the same process to see if that child had any children of it’s own.

I know it sounds wierd, but if you sit and think about it for three hours you’ll get it. lol

Case closed on this one, I guess.

Hi.

I don’t know if you’ve seen this but in the MAXScript reference, under the section dedicated to the TreeView ActiveX Control, at the bottom of the page, there’s a link to a sample script called How To … Develop a Scene Browser using TreeView ActiveX Control.

That could help you!.

Greets.