Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scan Treeview's nodes in order they appear on screen
Message
From
24/11/2003 17:42:09
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00853065
Message ID:
00853103
Views:
19
Hi Sylvain;
>
>We wanted to scan all the nodes in the treeview one by one and rebuild the table on which it was orginally created so that next time it's opened, all the nodes will appear in the exact same order the user added them, but the Index property is corresponding to the order in which the items were added.
>
>How can we scan the treeview's nodes in the order they are displayed ? Or if not possible, how can we save the user's modification to the treeview ?
>

We do it using a recursive search.. Something like:
thisform.savingtv(thisform.mytreeview)


procedure savingtv
Lparameters myTV
Local nwindice,nwultindice
if  used("cur_tv")
    sele cur_tv
    use
endif
sele 0
create cursor cur_tv (buffer_rec c(250))

With myTV
    nwind                        = .Nodes(1).Root.FirstSibling.Index
    nwultindice                  = .Nodes(1).Root.LastSibling.Index
    this.Geting_Sub_Nodes(nwind, myTV)
    Do While nwindice # nwultindice
        nwindice = .Nodes(nwindice).Next.Index
        this.Geting_Sub_Nodes(nwindice,toTV)
    Enddo
Endwith
Return

procedure Geting_Sub_Nodes
Lparameters tnIndex, myTV
Local tnIndex, nwindex, nwlastindex
With myTV
    this.Writing_to_Node(tnIndex,myTV)
    If  .Nodes(tnIndex).Children > 0
        nwindex                    = .Nodes(tnIndex).Child.Index
        nwlastindex                = .Nodes(tnIndex).Child.LastSibling.Index
        this.Geting_Sub_Nodes(nwindex,myTV)
        Do  While nwindex # nwlastindex
            nwindex                = .Nodes(nwindex).Next.Index
            this.Geting_Sub_Nodes(nwindex,myTV)
        Enddo
    Endif
Endwith

procedure Writing_to_Node
Lparameters tnCurIndex, myTV
Local lnRootIndex, lnIndex, lcPrefix, lcKey, lnLevel
lnIndex                             = tnCurIndex
With myTV
    lnRootIndex                     = .Nodes(lnIndex).Root.Index
    lcPrefix                        = '  ' + .Nodes(lnIndex).Text
    lnLevel                         = 0
    IF  .Nodes(lnIndex).TAG = "LEVEL1"  && I use it when populating a treeview.. for 1st. parent
    else
        Do  While lnIndex # lnRootIndex .and. .Nodes(lnIndex).tag # "LEVEL1"
            lnIndex                     = iif(type(".Nodes(lnIndex).Parent.Index")<>"U",.Nodes(lnIndex).Parent.Index, lnRootIndex)
            lcPrefix                    = Iif(.Nodes(lnIndex).LastSibling.Index = ;
                                          lnIndex,' ',' ')+Space(3)+lcPrefix
            lnLevel                     = lnLevel + 1
        Enddo
    endif
    m.buffer_rec                        = lcPrefix
    insert into cur_tv from memvar
Endwith
As result the function will return a cursor: cur_tv

HTH

Claudio
"Now to him who is able to do immeasurably more than all we ask or imagine, according to his power that is at work within us, Ephesians 3:20
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform