TreeView1.BorderStyle = 1 
TreeView1.Style = tvwTreelinesPlusMinusPictureText
TreeView1.Nodes.ClearDim nodX As Node
   Set nodX = TreeView1.Nodes.Add(, , dbname, dbname)For i = 0 To rst.RecordCount - 1
  a(i) = i
  Set nodX = TreeView1.Nodes.Add(dbname, tvwChild, , a(i))
 nodX.EnsureVisible
Next i你在 Set nodX = TreeView1.Nodes.Add(dbname, tvwChild, , a(i))之前判断是否需要写上tvwchild参数不就可以了吗if ***** then
 Set nodX = TreeView1.Nodes.Add(dbname, tvwChild, , a(i))
else
  Set nodX = TreeView1.Nodes.Add(dbname, , , a(i))
end if

解决方案 »

  1.   

    这是一个 通过用ADO 读入数据放入 Treeview 的例子。
    不要忘了 引用 ADO Library
    ==============================================================
    Option Explicit' The database connection.
    Private m_Conn As ADODB.Connection
    ' List the records in this table.
    Private Sub LoadRecords(ByVal table_node As Node)
    Dim rs As ADODB.Recordset
    Dim i As Integer
    Dim record_text As String
    Dim record_node As Node    ' Do nothing if the table's records are already loaded.
        If table_node.Children > 0 Then Exit Sub    ' Get the table's records.
        Set rs = m_Conn.Execute( _
            "SELECT * FROM " & table_node.Text, , adCmdText)
        Do Until rs.EOF
            ' Build the record string.
            record_text = ""
            For i = 0 To rs.Fields.Count - 1
                record_text = record_text & ", " & rs.Fields.Item(i)
            Next i
            record_text = Mid$(record_text, 2)        ' Add the record node.
            Set record_node = trvData.Nodes.Add(table_node, tvwChild, , record_text)
            record_node.Tag = "Record"
            record_node.EnsureVisible        ' Get the next record.
            rs.MoveNext
        Loop    rs.Close
    End Sub' List the tables in the database.
    Private Sub ListTables()
    Dim rs As ADODB.Recordset
    Dim table_node As Node    ' Clear the TreeView.
        trvData.Nodes.Clear    ' Use OpenSchema and get the table names.
        Set rs = m_Conn.OpenSchema(adSchemaTables, _
            Array(Empty, Empty, Empty, "Table"))
        Do While Not rs.EOF
            Set table_node = trvData.Nodes.Add(, , , rs!TABLE_NAME)
            table_node.Tag = "Table"
            rs.MoveNext
        Loop    rs.Close
    End Sub
    Private Sub Form_Load()
    Dim db_file As String    ' Get the database file name.
        db_file = App.Path
        If Right$(db_file, 1) <> "\" Then db_file = db_file & "\"
        db_file = db_file & "Data.mdb"    ' Open the database connection.
        Set m_Conn = New ADODB.Connection
        m_Conn.ConnectionString = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & db_file & ";" & _
            "Persist Security Info=False"
        m_Conn.Open    ' Load the table names into the ListView.
        ListTables
    End Sub
    Private Sub Form_Resize()
        trvData.Move 0, 0, ScaleWidth, ScaleHeight
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        m_Conn.Close
    End Sub
    Private Sub trvData_NodeClick(ByVal Node As MSComctlLib.Node)
        ' See what kind of node this is.
        Select Case Node.Tag
            Case "Table"
                ' Load this table's records.
                LoadRecords Node
            Case "Record"
                MsgBox "Record" & Node.Text
        End Select
    End Sub