This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
web:tree [2019/03/17 13:47]
agcyphers [Examples]
web:tree [2019/06/21 14:35] (current)
agcyphers [Examples]
Line 78: Line 78:
 firstItemFirstChild.Checkbox = True firstItemFirstChild.Checkbox = True
 me.AddItem( firstItemFirstChild,​ firstItem )</​code>​ me.AddItem( firstItemFirstChild,​ firstItem )</​code>​
 +=== Iterate Items ===
 +As GraffitiWebTree items are maintained in a relational manner (using Parents and Children), iterating items can be a tough concept to grasp. The easiest path is to create a method to do your multi-level iteration and perform a specific function. For instance, the following code will loop through all items in the tree and give you an opportunity to do something with the individual item's CheckValue property:
 +<code xojo>​Private Sub StoreCheckValues(ofTree as GraffitiWebTree,​ inNode as GraffitiWebTreeItem = Nil)
 +  dim arrCheck() as GraffitiWebTreeItem
 +  if not IsNull( inNode ) Then
 +    arrCheck = inNode.Children
 +  else
 +    arrCheck = ofTree.Items
 +  end if
 +  ​
 +  dim intCycle as Integer
 +  dim intMax as Integer = arrCheck.Ubound
 +  ​
 +  '// Note that you will want to perform the same operation on the parent
 +  ' ​  ​before the loop if you're providing inNode and want its value recorded.
 +  ​
 +  dim currentItem as GraffitiWebTreeItem
 +  for intCycle = 0 to intMax
 +    currentItem = arrCheck(intCycle)
 +    ​
 +    if currentItem.Checkbox then '// Has a checkbox
 +      '// Store the value of CheckValue
 +    end if
 +    ​
 +    '// The following line will iterate over the children of currentItem.
 +    ' ​  If you only want to do top-level children then you can comment this
 +    ' ​  or add a method parameter and check it here.
 +    if currentItem.Children.Ubound >= 0 then StoreCheckValues( ofTree, currentItem )
 +  next
 +End Sub</​code>​
 +Then you would simply call the method and pass in your tree to iterate through all items:
 +<code xojo>​StoreCheckValues(myTreeInstance)</​code>​
 +Or, if you only want to iterate over a specific branch of the tree:
 +<code xojo>​StoreCheckValues(myTreeInstance,​ myBranchTreeItem)</​code>​