TreeView用于数据库Dim DB As Database
Dim RS As Recordset
Dim i As Integer
Dim nodex As Node
Dim j As String
Dim itemx As ListItem
Dim itemy As ListItem
Dim flag As Boolean
Private Sub Command1_Click()
TreeView1.LineStyle = tvwRootLines
Set nodex = TreeView1.Nodes.Add(, , "r", "Root")
For i = 0 To 25
Set nodex = TreeView1.Nodes.Add("r", tvwChild, Chr(65 + i), Chr(65 + i))
RS.MoveFirst
Do While Not RS.EOF
If UCase(Left(RS!Name, 1)) = Chr(65 + i) Then
Set nodex = TreeView1.Nodes.Add(Chr(65 + i), tvwChild, , RS!Name)
End If
RS.MoveNext
Loop
Next
Command1.Enabled = False
End Sub
Private Sub Form_Load()
Set DB = OpenDatabase(App.Path & "\sigma1.mdb")
Set RS = DB.OpenRecordset("master")
flag = False
End Sub
Private Sub TreeView1_Click()
On Error Resume Next
RS.MoveFirst
If flag = True Then
j = TreeView1.Nodes.Item(TreeView1.SelectedItem.Index)
If Not j = "Root" Then
RS.Index = "mastname"
RS.Seek "=", j
ListView1.ColumnHeaders.Clear
ListView1.ListItems.Clear
Dim itemx As ListItem
ListView1.ColumnHeaders.Add 1, "a", "Name", ListView1.Width / 2
ListView1.ColumnHeaders.Add 2, "b", "City", ListView1.Width / 2
Set itemx = ListView1.ListItems.Add(, , RS!Name)
itemx.SubItems(1) = RS!city
ListView1.View = lvwReport
End If
End If
Exit Sub
erus:
MsgBox Err.Description
End Sub
Private Sub TreeView1_Collapse(ByVal Node As ComctlLib.Node)
flag = False
End Sub
Private Sub TreeView1_Expand(ByVal Node As ComctlLib.Node)
flag = True
End Sub