我想在treeview里实现下面的功能:
(1):数据库形式
ID 数量 日期
1001 200 2006-10-23
1002 123 2006-10-23
1003 500 2006-10-24
1004 770 2006-10-24
(2):我想在treeview里表现出来的形式:
+ 2006-10-23 ' + 代表父节点,- 代表子节点
- 200
- 123
+ 2006-10-24
- 500
- 770
现在的问题是,我该怎么实现呢??还有,node.key这个属性除了不能是数字以外还有什么要求么?
我自己写的代码是这样的:
Dim sql As String
sql = "select 日期 from 表 group by 日期 having count(日期) > 0"
Adodc1.ConnectionString = adocon
Adodc1.RecordSource = sql
Adodc1.RefreshDo While Adodc1.Recordset.EOF = False
sql = " select * from 表 where 日期 ='" & Adodc1.Recordset.Fields("日期") & "'"
Adodc2.ConnectionString = adocon
Adodc2.RecordSource = sql
Adodc2.Refresh
i = 1
Do While Adodc2.Recordset.EOF = FalseIf i = 1 Then
Dim node As node
Set node = TreeView1.Nodes.Add()
node.Text = Adodc2.Recordset.Fields("日期")
node.Key = "id" & Adodc2.Recordset.Fields("ID")
node.Image = 3
End If
Set node1 = TreeView1.Nodes.Add("id" & Adodc2.Recordset.Fields("ID"), tvwChild)
node1.Text = Adodc2.Recordset.Fields("单据编号")
node1.Key = Adodc2.Recordset.Fields("ID")
node1.Image = 2
i = 2
Loop
Loop我自己都觉得写得很白痴,希望大家帮帮我........谢谢了!!:'''(
(1):数据库形式
ID 数量 日期
1001 200 2006-10-23
1002 123 2006-10-23
1003 500 2006-10-24
1004 770 2006-10-24
(2):我想在treeview里表现出来的形式:
+ 2006-10-23 ' + 代表父节点,- 代表子节点
- 200
- 123
+ 2006-10-24
- 500
- 770
现在的问题是,我该怎么实现呢??还有,node.key这个属性除了不能是数字以外还有什么要求么?
我自己写的代码是这样的:
Dim sql As String
sql = "select 日期 from 表 group by 日期 having count(日期) > 0"
Adodc1.ConnectionString = adocon
Adodc1.RecordSource = sql
Adodc1.RefreshDo While Adodc1.Recordset.EOF = False
sql = " select * from 表 where 日期 ='" & Adodc1.Recordset.Fields("日期") & "'"
Adodc2.ConnectionString = adocon
Adodc2.RecordSource = sql
Adodc2.Refresh
i = 1
Do While Adodc2.Recordset.EOF = FalseIf i = 1 Then
Dim node As node
Set node = TreeView1.Nodes.Add()
node.Text = Adodc2.Recordset.Fields("日期")
node.Key = "id" & Adodc2.Recordset.Fields("ID")
node.Image = 3
End If
Set node1 = TreeView1.Nodes.Add("id" & Adodc2.Recordset.Fields("ID"), tvwChild)
node1.Text = Adodc2.Recordset.Fields("单据编号")
node1.Key = Adodc2.Recordset.Fields("ID")
node1.Image = 2
i = 2
Loop
Loop我自己都觉得写得很白痴,希望大家帮帮我........谢谢了!!:'''(
Set node = TreeView1.Nodes.Add()
node.Text = Adodc2.Recordset.Fields("日期")
node.Key = "id" & Adodc2.Recordset.Fields("ID")
node.Image = 3
End If
提到
sql = " select * from 表 where 日期 ='" & Adodc1.Recordset.Fields("日期") & "'"
这句之前
Adodc2改为Adodc1 不过你日期节点的key得重新表示 和ID没关系自己再测测 偶未试
sql = "select 日期 from 表 group by 日期 having count(日期) > 0"
Adodc1.ConnectionString = adocon
Adodc1.RecordSource = sql
Adodc1.RefreshDo While Adodc1.Recordset.EOF = False
Dim node As node
Set node = TreeView1.Nodes.Add(, , Adodc1.Recordset.Fields("日期") & " ", Adodc1.Recordset.Fields("日期"), 3, 3)
sql = " select * from aad where 日期 = #" & Adodc1.Recordset.Fields("日期") & "#"
Adodc2.ConnectionString = adocon
Adodc2.RecordSource = sql
Adodc2.Refresh
Do While Adodc2.Recordset.EOF = False
Set node = TreeView1.Nodes.Add(Adodc2.Recordset.Fields("日期") & " ", tvwChild, "id" & Adodc2.Recordset.Fields("ID"), Adodc2.Recordset.Fields("ID"), 2, 2)
Adodc2.Recordset.MoveNext
Loop
Adodc1.Recordset.MoveNext
Loop