[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Populate Treeview Not Using Recursive Logic

Hello everyone,

    I have some data (recordset) that looks like this...there are a number of other columns that have descriptions and totals for the job, phase and task, however, they are just filler columns.  The 3 columns that I would like the tree built on are listed.


Job #       Phase  Task  
----------- -----     -----
IMP S       NULL   NULL  
IMP1        NULL   NULL
IMP3        00000 00010
IMP3        00000 00020      
IMP3        00000 00030
IMP3        00000 00040
IMP3        00000 00050        
IMP3        00000 00060
IMP3        00000 00127    
IMP3        00000 00180
IMP3        00000 00499
IMP3        00500 00520      
IMP3        00500 00750
IMP3        00500 00970
IMP3        00500 00990
IMP3        01000 01010    
IMP3        01000 01070        
IMP9       NULL  NULL

    How do I put this into a tree view.  Notice there is no recusive logic in this table.  I've populated another tree view control using recusive logic code which calls a procedure until the tree is populated.  That seems simple compared to this...Not sure what I'm missing.

    I can't seem to figure this one out.  I've been looking for documentation on the tree view, but the help file is no where to be found.  

    I was using this code from rockiroads that was posted a while back, but his only had two levels and not three.  

Thanks in advance,
Mike



0
Data-Man
Asked:
Data-Man
  • 5
  • 2
1 Solution
 
Data-ManAuthor Commented:
I was looking for something a little more difinitive.  I was able to get it to work, but there has to be an easier way.  Here is my code.

    Me.tvStructure.Nodes.Clear
   
    'Build the Root Nodes
    Do While Not rstTemp.EOF
   
        'If any of the name changes then we have a new parent
        If rstTemp("Job #") <> strRootNode Then
            Me.tvStructure.Nodes.Add , , "Job # " & rstTemp("Job #"), rstTemp("Job #") & " " & rstTemp("Job Name") & " " & rstTemp("Job Total") & " " & rstTemp("Township Total")
        End If
       
        strRootNode = rstTemp("Job #")
   
        rstTemp.MoveNext
    Loop

    rstTemp.MoveFirst
    strRootNode = ""
   
    'Build the First Level Nodes
    Do While Not rstTemp.EOF
   
        'If any of the name changes then we have a new parent
        If (rstTemp("Job #") <> strRootNode Or rstTemp("Phase") <> strFirstNode) And (IsNull(rstTemp("Phase")) = False And rstTemp("Phase") <> strFirstNode) Then
            Me.tvStructure.Nodes.Add "Job # " & rstTemp("Job #"), tvwChild, "Phase " & rstTemp("Phase"), rstTemp("Phase") & " " & rstTemp("Phase Description") & " " & rstTemp("Phase Total") & " " & rstTemp("Township Phase Total")
        End If
       
        strFirstNode = Nz(rstTemp("Phase"), "None")
        strRootNode = rstTemp("Job #")
       
        rstTemp.MoveNext
    Loop
       
    rstTemp.MoveFirst
    strRootNode = ""
    strFirstNode = ""

    'Build the Second Level Nodes
    Do While Not rstTemp.EOF

        'If any of the name changes then we have a new parent
        If (rstTemp("Job #") <> strRootNode Or rstTemp("Task") <> strFirstNode) And (IsNull(rstTemp("Task")) = False And rstTemp("Task") <> strSecondNode) Then
            Me.tvStructure.Nodes.Add "Phase " & rstTemp("Phase"), tvwChild, "Task " & rstTemp("Task"), rstTemp("Task") & " " & rstTemp("Task Description") & " " & rstTemp("Task Total") & " " & rstTemp("Township Task Total")
        End If

        strSecondNode = Nz(rstTemp("Task"), "None")
        strFirstNode = Nz(rstTemp("Phase"), "None")
        strRootNode = rstTemp("Job #")

        rstTemp.MoveNext
    Loop
0
 
flavoCommented:
hmm..

pseudo code

make sure your rs is odered by Job # and Phase  



while not rs.eof

      sRoot = rs("job")
      Add parent node
         while sRoot = rs("job")
             Add first child
                sChile = rs("phase")
                     while rs("phase") = sChild
                           Add second child
                           rs.movenext
                      wend
                      rs.movenext
                 wend
              rs.movenext
        wend

just one loop

????
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Data-ManAuthor Commented:
I was thinking along those lines, but I couldn't sus out the logic...so I broke it down into 3 groups.  Maybe my brain is wired funny...but the more complicated and convoluted the solution...the essier it is for me to understand....LOL

Mike
0
 
flavoCommented:
i think you'd also need

 Comment from flavo
Date: 11/24/2004 08:13AM EST
ID: 12660098
 Your Comment  


Mike,

Seen the MSDN help?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingtreeviewcontrol.asp
&
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingtreeviewcontrol.asp
 
Comment from Data-Man
Date: 11/24/2004 08:21AM EST
ID: 12660154
 Author Comment  


I was looking for something a little more difinitive.  I was able to get it to work, but there has to be an easier way.  Here is my code.

    Me.tvStructure.Nodes.Clear
   
    'Build the Root Nodes
    Do While Not rstTemp.EOF
   
        'If any of the name changes then we have a new parent
        If rstTemp("Job #") <> strRootNode Then
            Me.tvStructure.Nodes.Add , , "Job # " & rstTemp("Job #"), rstTemp("Job #") & " " & rstTemp("Job Name") & " " & rstTemp("Job Total") & " " & rstTemp("Township Total")
        End If
       
        strRootNode = rstTemp("Job #")
   
        rstTemp.MoveNext
    Loop

    rstTemp.MoveFirst
    strRootNode = ""
   
    'Build the First Level Nodes
    Do While Not rstTemp.EOF
   
        'If any of the name changes then we have a new parent
        If (rstTemp("Job #") <> strRootNode Or rstTemp("Phase") <> strFirstNode) And (IsNull(rstTemp("Phase")) = False And rstTemp("Phase") <> strFirstNode) Then
            Me.tvStructure.Nodes.Add "Job # " & rstTemp("Job #"), tvwChild, "Phase " & rstTemp("Phase"), rstTemp("Phase") & " " & rstTemp("Phase Description") & " " & rstTemp("Phase Total") & " " & rstTemp("Township Phase Total")
        End If
       
        strFirstNode = Nz(rstTemp("Phase"), "None")
        strRootNode = rstTemp("Job #")
       
        rstTemp.MoveNext
    Loop
       
    rstTemp.MoveFirst
    strRootNode = ""
    strFirstNode = ""

    'Build the Second Level Nodes
    Do While Not rstTemp.EOF

        'If any of the name changes then we have a new parent
        If (rstTemp("Job #") <> strRootNode Or rstTemp("Task") <> strFirstNode) And (IsNull(rstTemp("Task")) = False And rstTemp("Task") <> strSecondNode) Then
            Me.tvStructure.Nodes.Add "Phase " & rstTemp("Phase"), tvwChild, "Task " & rstTemp("Task"), rstTemp("Task") & " " & rstTemp("Task Description") & " " & rstTemp("Task Total") & " " & rstTemp("Township Task Total")
        End If

        strSecondNode = Nz(rstTemp("Task"), "None")
        strFirstNode = Nz(rstTemp("Phase"), "None")
        strRootNode = rstTemp("Job #")

        rstTemp.MoveNext
    Loop
 
Comment from flavo
Date: 11/24/2004 08:27AM EST
ID: 12660195
 Your Comment  


hmm..

pseudo code

make sure your rs is odered by Job # and Phase  



while not rs.eof

      sRoot = rs("job")
      Add parent node
         while sRoot = rs("job") and not rs.eof
             Add first child
                sChile = rs("phase")
                     while rs("phase") = sChild and not rs.eof
                           Add second child
                           rs.movenext
                      wend
                      rs.movenext
                 wend
              rs.movenext
        wend
 
to stop errors (ie looping too far - past the end of the rs)
0
 
flavoCommented:
woops!  copied waaaaaaay tooooooo much!


while not rs.eof

      sRoot = rs("job")
      Add parent node
         while sRoot = rs("job") and not rs.eof
             Add first child
                sChile = rs("phase")
                     while rs("phase") = sChild and not rs.eof
                           Add second child
                           rs.movenext
                      wend
                      rs.movenext
                 wend
              rs.movenext
        wend
 
to stop errors (ie looping too far - past the end of the rs)
0
 
flavoCommented:
You got it :-)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now