>IDN Name Parent Gender >1 Silver 3 Horse >2 Golden 3 Mare >3 Silverado 0 Horse >>
>LOCAL lcNodeKey, lcNodeText >thisform.AddObject('tree1', 'olecontrol', 'COMCtl.treectrl') >WITH thisform.tree1 > .visible = .t. > .height = 250 &&thisform.height - 180 > .width = 300 &&thisform.width - 165 > .left = 16 > .top = 2 >ENDWITH >>
>Thisform.tree1.Nodes.Clear() > >*** Get the record where the paretn_id is zero >*** This is the root node >*IF SEEK( 0, [FamilyData], [Parent_fk] ) >IF SEEK( thisform.combo1.Value , "cv", "idn") > *** This is the root level node so add it > lcNodeKey = [P] + ALLTRIM(transform(thisform.combo1.value)) && [P] + TRANSFORM( FamilyData.Person_pk) > lcNodeText = ALLTRIM(thisform.combo1.DisplayValue) && ALLTRIM( FamilyData.FirstName ) + [ ] + ALLTRIM( FamilyData.LastName ) > Thisform.Tree1.Nodes.Add( , , lcNodeKey, lcNodeText ) >*SET STEP ON > *** Now go ahead and add any child nodes to the tree > Thisform.ExplodeKids ( thisform.combo1.Value ) >ENDIF > >*** Now select the root rode in the tree >Thisform.Tree1.Nodes( 1 ).Selected = .T. >>
>LPARAMETERS tiParentFK >tiParentFK = VAL(tiParentFK) >#DEFINE tvwFirst 0 && First sibling >#DEFINE tvwLast 1 && Last sibling >#DEFINE tvwNext 2 && Next sibling >#DEFINE tvwPrevious 3 && Previous sibling >#DEFINE tvwChild 4 && Child > >LOCAL liRecNo, lcParentKey, lcNodeKey, lcNodeText > >*** Save the record pointer >liRecNo = RECNO( "cv" ) >SET STEP ON >*** See if we have any children for the >*** passed in PK - The table is already >*** in ParentFK order >IF SEEK( tiParentFK, "cv", "padre" ) > SELECT cv > *IF TYPE(tiParentFK)= "C" THEN > * tiParentFK= VAL(tiParentFK) > *ENDIF > SCAN WHILE cv.padre = tiParentFK > *** Add the child node to the tree > lcNodeKey = [P] + TRANSFORM( cv.idn ) > lcNodeText = ALLTRIM( cv.nombre ) &&+ [ ] + ALLTRIM( FamilyData.LastName ) > lcParentKey = [P] + ALLTRIM(TRANSFORM( tiParentFK )) > Thisform.Tree1.Nodes.Add( lcParentKey, tvwChild , lcNodeKey, lcNodeText ) > Thisform.Tree1.Nodes( lcParentKey ).Expanded = .T. > > *** Explode the child > Thisform.ExplodeKids(TRANSFORM(cv.idn)) > ENDSCAN >ENDIF > >*** Reposition record pointer >GO liRecNo IN cv >Here is a problem, I believe:
scan while ... *** Explode the child Thisform.ExplodeKids(TRANSFORM(cv.idn)) && uses scan while ENDSCANI'm not sure, but I think you need to move ExplodeKids outside the loop and do it as a separate loop. Otherwise you're scanning the table, then scan the same table with different PK, etc.