David, I have removed all comments and just will give you the bare bones with prototypes. first lets erase and initialize the tree view control, so Call: Sub Get_Tree( dObj) 'Prototype: ResetTreeView( dObj, treeId, nodeName, nodeData) ResetTreeView dObj, MyTreeName, "A Name", 0
'Make the tree: 'Prototype: GetAllTreeLeaves( treeName, lastNode, dObj, dArray) GetAllTreeLeaves MyTreeName, dObj.Control( MyTreeName).Root, dObj, treeLeaveNames 'Now go to the top level for focus: 'Actual: dObj.Control( MyTreeName).Focus() Queue "SetTreeFocus", dObj.Control( MyTreeName) End Sub Sub ResetTreeView( dObj, treeId, nodeName, nodeData) 'Reset programs Tree View level based on ID. dObj.Control( treeId).Clear ' clearing the control based on id, just plain removing it since we are in reset mode. 'Now below we are making the tree all over again, starting at it's root: Dim tvRoot Set tvRoot = dObj.Control( treeId).NewItem ' Attaching the very first item on the tree above, it's first limb, in this case, the trunck. 'Below attaching a name to the first item and a ID (data) which is exposed when selected or clicked on: tvRoot.Text = nodeName tvRoot.Data = nodeData ' Remember David the node data is what you assign to it, a number. 'The text, can be anything, such as a color name. 'Note: above is for the actual trunck, the top of the tree, so below: dObj.Control( treeId).TopLevel.Insert tvRoot, tviRoot 'Note: The text and ID you gave it is now at the top of the tree. ' Above is the actual insert command and being inserted is the item called tvRoot, which you made above it. End Sub ' End of the making of a tree. 'Making leaves of the tree an array has to be passed in. ' The array is either the program list or the list of choice of listings, like your colors or pants and such. ' Any sub call is another routine just like this for the lists sub options. 'The array can be any multidimensional array of all your data. 'Remember what Rick had said, this can be done recursively until all branches and leaves have been made. Sub GetAllTreeLeaves( treeName, lastNode, dObj, dArray) ' Note above the name lastNode, the node that gets a new branch. 'Note: we are getting all needed values for the children being made, including the array counter. Dim tChildName, tCount, tMax, tLevel, tSubLevel, i, j Dim tvNewChild, tvNewChildChildren, tvNewChildChildrensChildren, tvNewChildChildrensChildrensSibblings 'Note: all arrays start at 0 or 0 based. 'But, you do not have to and you can use the same convention trees do where the first item in the collection is 1. tCount = -1 For Each tChildName In dArray ' Now lets get all the array items to store in the limbs leaves. tCount = tCount + 1 'Note if you have an array of several dimensions, you want the max of that dimension, which is done below: 'Where tCount is the count of columns inside the array. tMax = treeNameCount( tCount) 'Now making sure there are no spaces in the name: Trim( tChildName) ' Adding to the name if you want to, but that is just an option: If tChildName <> "" Then tChildName = "anything" & tChildName ' Now create sub tree level with a name and data. 'Note: The node values go in empty but comes back filled as a tree object: 'Note that the last item on the parameter list is an ID value for the data field: 'Prototype: GetChildNode treeIDName, lastNode, tvNewChild, dObj, tText, tData GetChildNode treeName, lastNode, tvNewChild, dObj, tChildName, tCount+1 ' Note: above is a leaf and below will be it's children. For i = 0 to tMax-1 ' Note below there is another array and that array is all your selections you want on the list, 'you can define it any way you want to: tChildName = arrayBySubChoices( i) If tChildName = "" Then tChildName = "No Name" ' Note: below is that power of ten ID level control I spoke about to identify what you have selected inside the data property 'You can use 10, 100, 1000, or 10000 for each using the mod to split them up. 'Based on no more than 999 items and 1000 children per: tLevel = (tCount+1) * 1000000 + i * 1000 'Now that you have the name, the level ID, now make the child of the leaf: 'Prototype: GetChildNode treeIDName, tvNewChild, tvNewChildChildren, dObj, tText, tData GetChildNode treeName, tvNewChild, tvNewChildChildren, dObj, tChildName, tLevel 'Note: The above routine is always used to make a child of a leaf... 'Below is the complete sub level of a given leaf of the tree, the second dimension of the array. 'This is only a 2 dimensional array but could be more based on how many levels you want in your tree. 'Note: you can do all of this recursively by sending in each time the next element of an array, or it's index. ' Count 1 to max for tree collection items start at 1. Dim itemNum: itemNum = 1 For j = 1 to maxColumns tSubLevel = tLevel + itemNum 'Based on less than 1000 sort and data fields. ' arrays start at 0 so column does also. 'But you can have everyting start at 1 to match the tree collection start point. tChildName = arrayOfChoices( i, j-1) If j <= maxSimpleColumns Then itemNum = itemNum + 1 'Prototype: GetChildNode treeIDName, tvNewChildChildren, tvNewChildChildrensChildren, dObj, tText, tData GetChildNode treeName, tvNewChildChildren, tvNewChildChildrensChildren, dObj, tChildName, tSubLevel End If Next ' Step Through each sub level. Next 'J. Next 'I End Sub 'Note: below is the making of each tree item: Sub GetChildNode( treeName, parentNode, tvINew, dObj, tvText, tvData) Set tvINew = dObj.Control( treeName).NewItem() tvINew.Text = tvText tvINew.Data = tvData ' Note below last node is parent and created is child. parentNode.Children.Insert tvINew, tviLast End Sub