Results 1 to 3 of 3

Thread: Algoritem to get data for TreeVieew

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    3

    Angry

    i need to get data from DB to fill a treeView with no limit to the treeview depth, i don't want to use recursive function because of overhead, if any one can give me an example of cod...

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Believe it or not, for this kind of thing my old COBOL experience comes in to play (I knew it would be good for something ). First, make sure your recordset is sorted by the appropriate keys (for example, let's say Region, State, City). Then, using the old COBOL concept of processing a file with "control breaks", you could set up a nested loop like the following:

    Code:
    Dim strPrevReg As String
    Dim strPrevState As String
    Dim strPrevCity As String
    ' ...
    ' ... add root node of tree
    rs.MoveFirst
    Do Until rs.EOF
        strPrevReg = rs!Region
        ' Add "grandfather" node for Region(one level below root)
        Do Until rs.EOF
            If strPrevReg <> rs!Region Then Exit Do
            strPrevState = rs!State
            'Add "father" node for State (2 levels below root)
            Do Until rs.EOF
                If strPrevState <> rs!State Then Exit Do
                strPrevCity = rs!City
                intCityCount = 0
                Do Until rs.EOF
                    If strPrevCity <> rs!City Then Exit Do
                    ' do processing, for example, count how
                    ' many records for a particular city
                    intCityCount = intCityCount + 1
                    rs.MoveNext
                Loop
                ' Add a "child" node for City (3 levels below root) possibly containing city name and count
                ' If there was only record per city, adding this node would go inside the previous loop
            Loop
        Loop




    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    Im not quite sure if thats what he ment... I think he ment that he can go down an unlimited number of nests(is nests the right word?), without needing to code for reach progressive son.. in which case the only sensible way is with recursive functions, but Id advise against that, just live with set sizes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width