使用Treeview控件,有错误,请帮忙。
Public Sub MakeTree(tvwX As TreeView)Dim nodX As Node
Dim sNodeKey As String
Dim sRelative As String
Dim MsgText As String
txtSQL = "select * from 系部"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加系
Do Until mrc.EOF
sNodeKey = "X" & mrc("系部代码").Value
Set nodX = tvwX.Nodes.Add(, , sNodeKey, mrc("系部名称").Value)
nodX.Tag = "系"
mrc.MoveNext
Loop
mrc.Close
txtSQL = "select * from 专业"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加专业
Do Until mrc.EOF
sNodeKey = "X" & mrc("专业代码").Value
sRelative = Mid$(sNodeKey, 1, 3)
Set nodX = tvwX.Nodes.Add(, , sNodeKey, mrc("专业名称").Value)
nodX.Tag = "专业"
mrc.MoveNext
Loop
mrc.Close
txtSQL = "select * from 班级"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'添加班级
Do Until mrc.EOF
sNodeKey = "X" & mrc("班号").Value
sRelative = Mid$(sNodeKey, 1, 5)
Set nodX = tvwX.Nodes.Add(, , sNodeKey, mrc("班级名称").Value)
nodX.Tag = "班级"
mrc.MoveNext
Loop
mrc.Close
Set tvwX.SelectedItem = tvwX.Nodes(1)
Set mrc = Nothing
Set nodX = Nothing
End Sub
Private Sub Form_Load()
Call comboAddItem(Combo2, "班级", 0)
Call comboAddItem(Combo3, "系部", 0)
Call MakeTree(TreeView1)
End Sub
代码是这样写的,可是显示的时候不分层啊,老是一下子全部显示出来了!请大家帮忙,
[ 本帖最后由 你好毒 于 2010-12-14 16:45 编辑 ]