Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with a code
Message
From
07/05/2007 11:16:50
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Problem with a code
Miscellaneous
Thread ID:
01223049
Message ID:
01223049
Views:
59
I have this problem with this code that helps me to find in the same table which are the parents of horses:
IDN   Name    Parent   Gender
1     Silver    3      Horse
2     Golden    3      Mare
3     Silverado 0      Horse
I have a form that let me know which are the parents of the horses, the problem is that it only shows one parent at the treeview when records with the same parent number are consecutive but doesn't works when aren't and don't know why, can you help me out? this is the code:

Form's init code
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
Command button's click code:
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.
Method's explodekids code:
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
Next
Reply
Map
View

Click here to load this message in the networking platform