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?