斑竹,有个问题求教啊!我做个程序:
’其中一个环节是通过treeview控件和datagrid控件,实现对名为“团费收缴明细表”数据库的信息显示。
‘代码如下:
Private Sub Form_Load()
'确保窗体改变时控件随之改变
'Call ResizeInit(Me)
Dim mynod As Node
Set mynod = TreeView1.Nodes.Add(, , "mingxi", "团费收缴明细", 1)
Set mynod = TreeView1.Nodes.Add("mingxi", tvwChild, "yiying", "一营", 2)
Set mynod = TreeView1.Nodes.Add("yiying", tvwChild, , "一连", 3)
Set mynod = TreeView1.Nodes.Add("yiying", tvwChild, , "二连", 3)
Set mynod = TreeView1.Nodes.Add("yiying", tvwChild, , "三连", 3)
Set mynod = TreeView1.Nodes.Add("mingxi", tvwChild, "erying", "二营", 2)
Set mynod = TreeView1.Nodes.Add("erying", tvwChild, , "四连", 3)
Set mynod = TreeView1.Nodes.Add("erying", tvwChild, , "五连", 3)
Set mynod = TreeView1.Nodes.Add("erying", tvwChild, , "六连", 3)
Set mynod = TreeView1.Nodes.Add("mingxi", tvwChild, "sanying", "三营", 2)
Set mynod = TreeView1.Nodes.Add("sanying", tvwChild, , "七连", 3)
Set mynod = TreeView1.Nodes.Add("sanying", tvwChild, , "八连", 3)
Set mynod = TreeView1.Nodes.Add("sanying", tvwChild, , "九连", 3)
mynod.EnsureVisible
End Sub
‘运行效果
团费收缴明细
+一营
-一连
二连
三连
+二营
-四连
五连
六连
+三营
-七连
八连
九连
’可是,做到这里我以后怎么也过不去了,我不知道怎么连接数据库。我想通过库里它们代码的区别来通过单击节点,在datagrid中显示选择的记录集。
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim dbs As Database, strsql As String, rst As Recordset
Set dbs = OpenDatabase("D:\My Documents\tfsjxt(ku)\glid.mdb")
Select Case Node.Text
Case "一连"
strsql = "select*from dataku where 代码='1L'"
Set rst = dbs.OpenRecordset(strsql, dbOpenDynaset)
AdodcDataGrid1.RecordSource = "select*from dataku where 代码='1L'"
Case "二连"
strsql = "select*from dataku where 代码='1L'"
Set rst = dbs.OpenRecordset(strsql, dbOpenDynaset)
AdodcDataGrid1.RecordSource = "select*from dataku where 代码='2L'"
End Select
End Sub
请大家帮帮忙啊,真是晕了啊,