Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where is my logic this morning?
Message
From
22/10/2003 11:11:40
 
 
To
22/10/2003 11:02:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00841000
Message ID:
00841073
Views:
19
What was I thinking????? :O) *G* (Obviously I wasn't!)

Thank you SOOOOOOOOOOOOO MUCH Cetin!

Tracy

>>I'm trying to step through a table to populate a treeview and I can't seem to get my 'head around it' this am. :o(
>>
>>My table's records looks like this:
>>
>>
>>* All parent values of A0 are top level branches - any self value of
>>* nothing in spaces 5 and 6 or the value of B1 in spaces 5 and 6 are top level.
>>* All other values in spaces 5 and 6 are sub levels and fall under the branch
>>* of its parent
>>
>>cPARENT        cSELF           SEQ
>>
>>A0             1MHG                    && top level message header
>>A0             2TRG            1829    && top level 1st transaction
>>A0             5BISB10001      1829    && top level
>>A0             9BISB10001      1829    && top level
>>5BISB10001     5BPIF10001      1829    && 2nd level branch, directly under 5BISB10001
>>5BPIF10001     5DRVF20001      1829    && 3rd level branch, directly under 5BPIF10001
>>5BPIF10001     5DRVF20002      1829    && 3rd level branch, directly under 5BPIF10001
>>5DRVF20001     6PDRF30001      1829    && 4th level branch, directly under 5DRVF20001
>>A0             2TRG            1830    && top level 2nd transaction
>>A0             5BISB10001      1830    && top level
>>A0             9BISB10001      1830    && top level
>>5BISB10001     5BPIF10001      1830    && 2nd level branch, directly under 5BISB10001
>>5BPIF10001     5DRVF20001      1830    && 3rd level branch, directly under 5BPIF10001
>>5BPIF10001     5DRVF20002      1830    && 3rd level branch, directly under 5BPIF10001
>>5DRVF20001     6PDRF30001      1830    && 4th level branch, directly under 5DRVF20001
>>5DRVF20001     6PDRF30002      1830    && 4th level branch, directly under 5DRVF20001
>>
>>Note: 1st four characters are type i.e. 5BPI, 5BIS, 1MHG, etc.
>>      5&6 are 'sortof' levels i.e. B1, F1, F2, etc
>>      7-10 is a counter that denotes it is the first, 2nd, etc 0001, 0002, etc.
>>      Records are stored in this order and each 2TRG record denotes the
>>      next 'group' or transaction
>>
>>The records should look like this in the treeview:
>>
>>1MHG                         && 1st Message
>>2TRG                         && 1st transaction or 'group' in this message
>>5BISB10001
>>    5BPIF10001               && 1st 5BPI under this 5BIS in 1st transactioin
>>        5DRVF20001           && 1st 5DRV under this 5BPI
>>        5DRVF20002           && 2nd 5DRV under this 5BPI
>>            6PDRF30001       && 1st 6PDR under this 5DRV
>>9BISB10001
>>2TRG                         && 2nd transaction or 'group' in this message
>>5BISB10001
>>    5BPIF10001               && 1st 5BPI under this 5BIS in 2nd transaction
>>        5DRVF20001           && 1st 5DRV under this 5BPI in 2nd transaction
>>        5DRVF20002           && 2nd 5DRV under this 5BPI in 2nd transaction
>>            6PDRF30001       && 1st 6PDR under this 5DRV in 2nd transaction
>>            6PDRF30002       && 2nd 6PDR under this 5DRV in 2nd transaction
>>9BISB10001
>>
>>
>>
>>All of the records in the treeview are in the table 'al3parnt' and the fields are cparent, cself, seq, ckey (quid key), etc...
>>
>>When the form's init is run I call the form's method addrecds which should populate the tree. I step through the table (tried it different ways) and try to populate the treeview appropriately.
>>
>>Here is my latest effort (a poor one at that):
>>
>>* The only way I seem to be able to determine which node to put the child under (reference it) is with the node.text value so far:
>>
>>
>>SELE Al3Parnt
>>set ORDER to 0
>>GO TOP
>>SCAN
>>	STORE RECNO('al3parnt') TO mrecno
>>	* al3parnt.cparent is the parent of this record or upper branch
>>	* al3parnt.cself is the identity of this record
>>	STORE al3parnt.seq TO mseq          &&  transaction sequence number
>>	IF al3parnt.cparent = "A0"          &&  this record's parent 'branch' A0 is always top level branch
>>		tNode = THISFORM.AddNode(oNode) &&  add this top level node
>>		tNode.Text = al3parnt.cSELF     &&  this record's identity
>>		tNode.Expanded = .T.
>>		tNode.Image = 1*5 + 1
>>		mtext = tNode.Text
>>		* Now create the child branches for this top level branch
>>		* based on the records' cparent field matching this record's cself field
>>		SCAN FOR ALLTRIM(UPPER(al3parnt.cparent)) = ALLTRIM(UPPER(mtext)) .and. al3parnt.seq=mseq
>>			xNode = THISFORM.AddNode(tNode)  && add the child branch to the above parent branch
>>			xNode.Text = al3parnt.cSELF       && this child branch's identity
>>			xNode.Expanded = .T.
>>			xNode.Image = 1*5 + 1
>>			mtext = xNode.Text
>>			*!* Here is where I get stuck
>>			* Now need to process this child record's sub branches if any, but my
>>			* logic is wrong because this obviously won't work.  I need to determine
>>			* how many levels it could possibly go or handle an infinite number of
>>			* sublevels (child branches)
>>		ENDSCAN
>>	ENDIF
>>	IF RECNO()<>mrecno
>>		GOTO mrecno
>>	ENDIF
>>ENDSCAN
>>
>>
>>Thanks to anyone willing to look at this! I get everything fine through the 2nd level only obviously...
>
>Tracy,
>Isn't there any typo ?
>What I get is :
>
>+-1MHG
>+-2TRG
>+-5BISB10001
>|   +-5BPIF10001
>|       +-5DRVF20001
>|       |   +-6PDRF30001
>|       +-5DRVF20002
>+-9BISB10001
>+-2TRG
>+-5BISB10001
>|   +-5BPIF10001
>|       +-5DRVF20001
>|       |   +-6PDRF30001
>|       |   +-6PDRF30002
>|       +-5DRVF20002
>+-9BISB10001
>
>
>Code below :
>
>Create Cursor Al3Parnt (cPARENT c(10),  cSELF c(10), SEQ i)
>Insert into Al3Parnt values ("A0             ","1MHG                    ",0 ) &&top level message header
>Insert into Al3Parnt values ("A0             ","2TRG            ",1829    ) && top level 1st transaction
>Insert into Al3Parnt values ("A0             ","5BISB10001      ",1829    ) && top level
>Insert into Al3Parnt values ("A0             ","9BISB10001      ",1829    ) && top level
>Insert into Al3Parnt values ("5BISB10001     ","5BPIF10001      ",1829    ) && 2nd level branch, directly under 5BISB10001
>Insert into Al3Parnt values ("5BPIF10001     ","5DRVF20001      ",1829    ) && 3rd level branch, directly under 5BPIF10001
>Insert into Al3Parnt values ("5BPIF10001     ","5DRVF20002      ",1829    ) && 3rd level branch, directly under 5BPIF10001
>Insert into Al3Parnt values ("5DRVF20001     ","6PDRF30001      ",1829    ) && 4th level branch, directly under 5DRVF20001
>Insert into Al3Parnt values ("A0             ","2TRG            ",1830    ) && top level 2nd transaction
>Insert into Al3Parnt values ("A0             ","5BISB10001      ",1830    ) && top level
>Insert into Al3Parnt values ("A0             ","9BISB10001      ",1830    ) && top level
>Insert into Al3Parnt values ("5BISB10001     ","5BPIF10001      ",1830    ) && 2nd level branch, directly under 5BISB10001
>Insert into Al3Parnt values ("5BPIF10001     ","5DRVF20001      ",1830    ) && 3rd level branch, directly under 5BPIF10001
>Insert into Al3Parnt values ("5BPIF10001     ","5DRVF20002      ",1830    ) && 3rd level branch, directly under 5BPIF10001
>Insert into Al3Parnt values ("5DRVF20001     ","6PDRF30001      ",1830    ) && 4th level branch, directly under 5DRVF20001
>Insert into Al3Parnt values ("5DRVF20001     ","6PDRF30002      ",1830    ) && 4th level branch, directly under 5DRVF20001
>
>* Define some constants.
>#Define tvwFirst	0
>#Define tvwLast	1
>#Define tvwNext	2
>#Define tvwPrevious	3
>#Define tvwChild	4
>
>#Define cnLOG_PIXELS_X 88
>#Define cnLOG_PIXELS_Y 90
>#Define cnTWIPS_PER_INCH 1440
>* 1440 twips per inch
>oForm = createobject('myForm')
>oForm.Show
>Read events
>
>Define CLASS myForm AS form
>
>
>  Top = 2
>  Left = 2
>  Height = 600
>  Width = 300
>  DoCreate = .T.
>  Caption = "TreeView - testpad"
>  BackColor = RGB(192,192,192)
>  Name = "myForm"
>  ShowWindow=2
>
>  Add OBJECT myTree AS olecontrol WITH ;
>    Top = 12, ;
>    Left = 0, ;
>    Height = 500, ;
>    Width = 300, ;
>    Name = "OleTreeView", ;
>    OleClass = 'MSComCtlLib.TreeCtrl'
>
>  *-- Fill the tree values
>  Procedure filltree
>  This.show
>With THIS.oletreeview.nodes
>
>SELE Al3Parnt
>set ORDER to 0
>SCAN
>	IF al3parnt.cparent = "A0"          &&  this record's parent 'branch' A0 is always top level branch
>		.add(,tvwFirst,Trim(al3parnt.cself)+'_'+Ltrim(Str(seq)),Trim(al3parnt.cSelf))
>	Else
>       .Add(Trim(al3parnt.cParent)+'_'+Ltrim(Str(seq)), tvwChild, ;
>            Trim(al3parnt.cself)+'_'+Ltrim(Str(seq)),Trim(al3parnt.cSelf))
>    endif
>EndScan
>EndWith
>Endproc
>
>  Procedure QueryUnload
>  Clear events
>Endproc
>
>
>  Procedure Init
>  Set TALK OFF
>  * Check to see if OCX installed and loaded.
>  If TYPE("THIS.oleTreeView") # "O" OR ISNULL(THIS.oletreeview)
>    Return .F.
>  Endif
>  With THIS.oletreeview
>    .linestyle =1
>    .labeledit =1
>    .indentation = 5
>    .PathSeparator = '\'
>    .Scroll = .t.
>    .OleDragMode = 0
>    .OleDropMode = 0
>  Endwith
>  This.filltree()
>  loTVUtils = CreateObject('TVUtils')
>  _cliptext = loTVUtils.tvlister(this.OleTreeView)
>Endproc
>
>
>  Procedure oletreeview.NodeClick
>  *** ActiveX Control Event ***
>  Lparameters node
>  Node.ensurevisible
>Endproc
>
>ENDDEFINE
>
>Define Class TvUtils as Line
>TVText = ''
>Procedure TVLister
>Lparameters toTV
>  Local lnIndex,lnLastIndex
>  this.TVText=''
>  With toTV
>    lnIndex     = .Nodes(1).Root.FirstSibling.Index
>    lnLastIndex = .Nodes(1).Root.LastSibling.Index
>    this._GetSubNodes(lnIndex,toTV,lnIndex)
>    Do While lnIndex # lnLastIndex
>      lnIndex = .Nodes(lnIndex).Next.Index
>     this._GetSubNodes(lnIndex,toTV,lnIndex)
>    Enddo
>  Endwith
>  Return this.TVText
>EndProc
>
>Procedure _GetSubNodes
>  Lparameters tnIndex, toTV, tnRootIndex
>  Local lnIndex, lnLastIndex
>  With toTV
>    this.WriteNode(tnIndex,toTV, tnRootIndex)
>    If .Nodes(tnIndex).Children > 0
>      lnIndex  = .Nodes(tnIndex).Child.Index
>      lnLastIndex = .Nodes(tnIndex).Child.LastSibling.Index
>      this._GetSubNodes(lnIndex,toTV,tnRootIndex)
>      Do While lnIndex # lnLastIndex
>        lnIndex = .Nodes(lnIndex).Next.Index
>        this._GetSubNodes(lnIndex,toTV,tnRootIndex)
>      Enddo
>    Endif
>  Endwith
>EndProc
>
>Procedure WriteNode
>  Lparameters tnCurIndex, toTV,tnRootIndex
>  Local lnRootIndex, lnIndex, lcPrefix, lcKey, lnLevel
>  lnIndex = tnCurIndex
>
>  With toTV
>    lcPrefix = '+-' + .Nodes(lnIndex).Text
>    lnLevel = 0
>    Do While lnIndex # tnRootIndex
>      lnIndex = .Nodes(lnIndex).Parent.Index
>      lcPrefix = Iif(.Nodes(lnIndex).LastSibling.Index = lnIndex,' ','|')+Space(3)+lcPrefix
>      lnLevel = lnLevel + 1
>    EndDo
>    this.TVText = this.TVText + lcPrefix + Chr(13)
>  EndWith
>endproc
>enddefine
>
>Cetin
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform