怎么样把数据库里的数据读到treeview中!弄了半天弄不好!急~有人在线么!
是不是定义两个rs记录集啊.希望还有人在线啊.我急啊!
如
父 子
0 1
0 2
0 3
1 4
1 5
1 6
2 7
2 8
3 9
3 10
怎么样把这个载入到treeview中啊
急死了..
[解决办法]
发错
=============================================
主表 T_main
ID M1 M2
1 a1 b1
2 a2 b2
3 a3 b3
-------------
次表 T_sub
ID S1 S2 mID
1 c1 d1 1
2 c2 d2 2
3 c3 d3 1
4 c4 d4 3
5 c5 d5 2
6 c6 d6 2
--------------------------
rs.Open "T_main ", conn, 1, 1
if not (rs.eof and rs.bof) then
'-------------------填充树节点---------------------
With treeview1.Nodes
.Add(, , "mytree ", "我的树 ").Tag = "root " '根
For k = 0 To rs.RecordCount - 1 '一级
.Add( "mytree ", tvwChild, "y1 " & k, rs(1)).Tag = rs(1)
strSQL = "SELECT * FROM T_sub WHERE mID= " & rs(0)
rs1.Open strSQL, conn, 1, 1
For m = 0 To rs1.Fields.Count - 1
.Add( "y1 " & k, tvwChild, "y2 " & k & m, rs1.Fields(m).Name).Tag = rs1(1)&m '二级
Next
rs1.Close
rs.MoveNext
next
rs.close
end with
end if
[解决办法]
Dim MyNode As Node
Dim FatherNode As String
Dim NodeKey As String
Dim NodeName As String
Dim ImageIndex As Integer
Set NewTRW.ImageList = Me.ImageList_Common
ImageIndex = 1
Set MyNode = NewTRW.Nodes.Add(, tvwFirst, NewOrganForm, "所有列表 ", ImageIndex) '加载根目录数据
Do Until Res0.EOF = True
FatherNode = Left(Res0.Fields( "OrganRank "), Len(Res0.Fields( "OrganRank ")) - 3)
NodeKey = Res0.Fields( "OrganRank ")
NodeName = Res0.Fields( "OrganName ")
'加载子目录数据
If FatherNode <> " " Then
Set MyNode = NewTRW.Nodes.Add(FatherNode, tvwChild, NodeKey, NodeName, ImageIndex)
End If
Res0.MoveNext
Loop
Res0.Close
' 表中字段结构
'==============================
OrganName OrganRank
所有列表ORC
1ORC001
2ORC002
3ORC001001
4ORC001001001
注:只通过一个表实现,但对于OrganRank插入时写个函数,就是形成一定的规律插入就行了