treeview树(利用数据表实现)带展开

Private Sub Form_Load()
'引用C:\windows\system32\MSCOMCTL.OCX,否则提示出错。
Dim Rec As New ADODB.Recordset
Dim stRecQL As String
Dim Item As Integer
Dim i As Integer
Dim Node1 As Node

Rec.Open "tblTreeview", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 0 To Rec.RecordCount - 1
If Rec!parentid = "S0000" Then
Set Node1 = Me.TreeView0.Nodes.Add(, , "S" & Rec!ID, Rec!ChildID)
Else
Set Node1 = Me.TreeView0.Nodes.Add("S" & Rec!parentid, tvwChild, "S" & Rec!ID, Rec!ChildID)
'Node1.index = True
End If
Rec.MoveNext
Next
For i = 1 To TreeView0.Nodes.Count
TreeView0.Nodes(i).Expanded = True '展开所有节点
Next i
Rec.Close
End Sub

转载于:https://www.cnblogs.com/ince/p/8980114.html

你可能感兴趣的:(treeview树(利用数据表实现)带展开)