Witam przedsatawiam przykład w VB6
Wyświetlenie struktury głównego drzewa
Kod:
Dim root As Long
Public Function GetRoot(tr As TreeView) As Long
Dim rs As New ADODB.Recordset
Dim gr As Long
On Error GoTo error
gr = 0
rs.Open "SELECT * FROM xt WHERE id=root AND super=1020 AND typ=12", SYcon, adOpenDynamic, adLockOptimistic
If rs.RecordCount = 1 Then
' Znalazlem root
tr.Nodes.Add , tvwFirst, "root", rs!kod, 1
tr.Nodes("root").Tag = rs!id
gr = rs!id
End If
rs.Close
Set rs = Nothing
GetRoot = gr
Exit Function
error:
MsgBox err.Description
End Function
Public Sub GetTree(tr As TreeView, root As Long)
Dim rs As New ADODB.Recordset
Dim ile_tree
On Error GoTo error
If root > 0 Then
rs.Open "SELECT * FROM xt WHERE super='" & root & "'", SYcon, adOpenDynamic, adLockOptimistic
ile_tree = rs.RecordCount
If ile_tree > 0 Then
For i = 1 To ile_tree
tr.Nodes.Add "root", tvwChild, "node_" & i, rs!kod, 3
tr.Nodes("node_" & i).Tag = rs!id
If rs!podkatalog > 0 Then
GetChilds tr, rs!id, "node_" & i
End If
rs.MoveNext
Next i
End If
rs.Close
Set rs = Nothing
End If
Exit Sub
error:
MsgBox err.Description, vbCritical
End Sub
root = GetRoot(Tree1) ' Towary
GetTree Tree1, root
Pozdrawiam.