|
9#
楼主 |
发表于 2007-1-17 18:48:00
|
只看该作者
是三级的啊:
Private Sub Form_Load()
TreeView.Nodes.Clear
strSQL = "SELECT 工厂ID,工厂名称 from 资料录入 "
strSQL = strSQL & "GROUP BY 工厂ID,工厂名称"
'先清空树控件的内容
Me.TreeView.Nodes.Clear
Set conn = CurrentProject.Connection
'按车间名称设置第一级"父"
Rec.Open strSQL, conn, adOpenKeyset, adLockOptimistic
For i = 0 To Rec.RecordCount - 1
Set nodindex = TreeView.Nodes.Add(, tvwChild, "父" & Rec.Fields("工厂ID"), Rec.Fields("工厂名称"), "K1", "K2")
nodindex.Sorted = True
Rec.MoveNext
Next
Rec.Close
'按部门名称设置第二级"子"
astrSQL = "SELECT 工厂ID,工厂名称,车间ID,车间名称 from 资料录入 "
astrSQL = astrSQL & "GROUP BY 工厂ID,工厂名称,车间ID,车间名称"
Rec.Open astrSQL, conn, adOpenKeyset, adLockOptimistic
For i = 0 To Rec.RecordCount - 1
Set nodindex = TreeView.Nodes.Add("父" & Rec.Fields("工厂ID"), tvwChild, "子" & Rec.Fields("车间ID") & Rec.Fields("工厂名称"), Rec.Fields("车间名称"), "K1", "K2")
nodindex.Sorted = True
Rec.MoveNext
Next
Rec.Close
'设置第三级"孙"
bstrSQL = "SELECT 工厂ID,工厂名称,车间ID,车间名称,部门ID,部门名称 from 资料录入 "
bstrSQL = bstrSQL & "GROUP BY 工厂ID,工厂名称,车间ID,车间名称,部门ID,部门名称"
Rec.Open bstrSQL, conn, adOpenKeyset, adLockOptimistic
For i = 0 To Rec.RecordCount - 1
Set nodindex = TreeView.Nodes.Add("子" & Rec.Fields("车间ID") & Rec.Fields("工厂名称"), tvwChild, "孙" & Rec.Fields("部门ID") & Rec.Fields("工厂名称") & Rec.Fields("车间名称"), Rec.Fields("部门名称"), "K1", "K2")
nodindex.Sorted = True
Rec.MoveNext
Next
Rec.Close
End Sub
|
|