PDA

Click to See Complete Forum and Search --> : Algoritem to get data for TreeVieew


shmul
Oct 20th, 2000, 11:09 AM
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...

BruceG
Oct 20th, 2000, 11:50 AM
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:


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

tonyenkiducx
Oct 23rd, 2000, 10:56 AM
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.