CREATE cursor mytable (code n(6), node N(6),child N(6),desc c(30)) APPEND from dbf('master') SELECT mytable REPLACE all child with val(substr(alltrim(str(code)),4,6)) REPLACE all node with val(substr(alltrim(str(code)),1,3)) REPLACE all child with 0 for(substr(alltrim(str(code)),4,6))="000" SELECT ; '_'+Padl(Node,5,'0')+Padl(Child,5,'0') As NodeId,; Iif(Child=0,space(11),'_'+Padl(Node,5,'0')+Padl(0,5,'0')) As ParentID,; desc As NodeText,TRIM(STR(code)) as code ; from mytable ; order By 1 ; into Cursor myTree SELECT myTree #DEFINE tvwFirst 0 #DEFINE tvwLast 1 #DEFINE tvwNext 2 #DEFINE tvwPrevious 3 #DEFINE tvwChild 4 WITH Thisform.OleTreeView.Nodes SCAN IF Empty(ParentID) oNode = .Add(,tvwFirst,NodeId,code+ ' '+Trim(NodeText)) oNode.ForeColor = RGB(0,0,0) ELSE oNode = .Add(ParentID,tvwChild,NodeId,code +' '+Trim(NodeText)) oNode.ForeColor = RGB(0,0,255) ENDIF ENDSCAN ENDWITH