treeview 不是数据约束控件,无法连接数据库!
表名就自动地作为一个节点了,各个字段就是一个子节点,记录还是用LISTVIEW来显示了!
呵呵
具体的范例看MSDN了,

解决方案 »

  1.   

    treeview不能绑定,自己写代码吧
      

  2.   

    你好好研究一下 visdata 的源代码。C:\Program Files\Microsoft Visual Studio\MSDN98\98VS\2052\SAMPLES\VB98\visdata
      

  3.   

    建议:
    你可以通过点击treeview的各个节点,增加一个datagrid空间,然后通过点击各个节点,显示不同数据库的不同表,可以通过代码动态的把datagrid连接到数据库的!我刚刚做完这方面的内容!!
      

  4.   

    Dim adoConnection As New ADODB.Connection
    Dim adoxCatalog As New ADOX.Catalog
    adoConnection.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=northwind;Server="
    'adoConnection.Open "Provider=MSDAORA.1;User ID=internal;Data Source=namepipe1;Persist Security Info=False"
    'adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Office2K\Office\Samples\Northwind.mdb;Persist Security Info=False"
    adoxCatalog.ActiveConnection = adoConnection
    'TreeView1.LineStyle = tvwRootLines
    TreeView1.Indentation = 400
    TreeView1.Nodes.Add , , "DataBase", "数据库: " & adoConnection.DefaultDatabase
    TreeView1.Nodes.Add "DataBase", tvwChild, "Table", "基本表"
    TreeView1.Nodes.Add "DataBase", tvwChild, "View", "视图"
    TreeView1.Nodes.Add "DataBase", tvwChild, "SystemTable", "系统表"
    'TreeView1.Nodes.Add "DataBase", tvwChild, "AccessTable", "Access 表"
    TreeView1.Nodes.Add "DataBase", tvwChild, "Object", "其它对象"
    Dim i As Integer
    Dim j As Integer
    Dim NodeX As Node
    For i = 0 To adoxCatalog.Tables.Count - 1
        'Debug.Print adoxCatalog.Tables.Item(i).Type
        Select Case adoxCatalog.Tables.Item(i).Type
               Case "TABLE"
                    Set NodeX = TreeView1.Nodes.Add("Table", tvwChild, adoxCatalog.Tables.Item(i).Name, adoxCatalog.Tables.Item(i).Name)
                    NodeX.Tag = adoxCatalog.Tables.Item(i).Type
               Case "VIEW"
                    Set NodeX = TreeView1.Nodes.Add("View", tvwChild, adoxCatalog.Tables.Item(i).Name, adoxCatalog.Tables.Item(i).Name)
                    NodeX.Tag = adoxCatalog.Tables.Item(i).Type
               Case "SYSTEM TABLE"
                    Set NodeX = TreeView1.Nodes.Add("SystemTable", tvwChild, adoxCatalog.Tables.Item(i).Name, adoxCatalog.Tables.Item(i).Name)
                    NodeX.Tag = adoxCatalog.Tables.Item(i).Type
               'Case "ACCESS TABLE"
               '     TreeView1.Nodes.Add "AccessTable", tvwChild, adoxCatalog.Tables.Item(i).Name, adoxCatalog.Tables.Item(i).Name
               Case Else
                    Set NodeX = TreeView1.Nodes.Add("Object", tvwChild, adoxCatalog.Tables.Item(i).Name, adoxCatalog.Tables.Item(i).Name)
                    NodeX.Tag = "Object"
        End Select    For j = 0 To adoxCatalog.Tables.Item(i).Columns.Count - 1
             Set NodeX = TreeView1.Nodes.Add(adoxCatalog.Tables.Item(i).Name, tvwChild, adoxCatalog.Tables.Item(i).Name & adoxCatalog.Tables.Item(i).Columns.Item(j).Name, adoxCatalog.Tables.Item(i).Columns.Item(j).Name)
        Next j
    Next i
    TreeView1.Nodes.Add "DataBase", tvwChild, "StoreProcedure", "存储过程"
    For i = 0 To adoxCatalog.Procedures.Count - 1
        Set NodeX = TreeView1.Nodes.Add("StoreProcedure", tvwChild, adoxCatalog.Procedures.Item(i).Name, adoxCatalog.Procedures.Item(i).Name)
    Next i