1

i'm currently building an application that requires me to dynamically fill a tree view i wrote the following code but the filling always stop at level 1

Private Sub TreeDraw(ByVal TreeRoot As String)
    'Throw New NotImplementedException
    TVNew.Nodes.Clear()
    Dim con = New OleDbConnection(StrConn)
    Dim strSql = "Select * from Tree WHERE TreeName = '" & _
        TreeRoot.Trim & "' AND levelNum = 0" & _
        " ORDER BY nodeID ASC"
    Dim da = New OleDbDataAdapter(strSql, con)
    Dim ds As New DataSet
    Dim lvl = 0

    Try
        da.Fill(ds, "Tree")
        Do While ds.Tables(0).Rows.Count > 0
            If lvl = 0 Then
                TVNew.Nodes.Add(ds.Tables(0).Rows(0)(4))
            Else
                For Each row As DataRow In ds.Tables(0).Rows
                    For Each node As TreeNode In TVNew.Nodes
                        If node.Text = row(3) Then
                            TVNew.SelectedNode = node
                            TVNew.SelectedNode.Nodes.Add(row(4))
                        End If
                    Next
                Next
            End If
            'MsgBox(lvl.ToString)
            lvl = lvl + 1

            da.Dispose()
            ds.Tables.Clear()

            strSql = "Select * from Tree WHERE TreeName = '" & _
                TreeRoot.Trim & "' AND levelNum =" & lvl & _
                " ORDER BY nodeID ASC"

            da = New OleDbDataAdapter(strSql, con)
            da.Fill(ds, "Tree")
        Loop
    Catch ex As Exception
        MsgBox(ex.Message & Chr(13) & da.SelectCommand.CommandText _
               , vbOKOnly, Application.ProductName)
        Exit Sub
    End Try

    TVNew.ExpandAll()

End Sub

can any one help please?

Fabio
  • 31,528
  • 4
  • 33
  • 72
  • Either you haven't bothered debugging your code or you haven't bothered providing us with the information gained when doing so. If you haven't debugged your code then you shouldn't be posting here. If you have then you need to describe EXACTLY where and how the behaviour of your code differs from your expectation. You don't fix code issues simply by reading the code. that's why VS has a debugger. – jmcilhinney Jun 18 '20 at 00:08
  • https://stackoverflow.com/q/805457/10216583 –  Jun 18 '20 at 13:32

0 Answers0