这是我的源码
Private Sub Form_Load()
DTPicker1.Value = Date
TreeView1.ImageList = ImageList1
TreeView1.LineStyle = 1
TreeView1.Style = 7
Adodc2.RecordSource = "select * from xibu"
Adodc2.CommandType = adCmdUnknown
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF
Key = "A" & Adodc2.Recordset.Fields("编号")
str1 = Adodc2.Recordset.Fields("系部")
Set node1 = TreeView1.Nodes.Add(, , Key, str1, 1)
Adodc3.RecordSource = "select * from zhuanye where 系别='" + Trim(Adodc2.Recordset.Fields("系部")) + "'"
Adodc3.CommandType = adCmdUnknown
Adodc3.Refresh
If Adodc3.Recordset.RecordCount > 0 Then
Adodc3.Recordset.MoveFirst
Do While Not Adodc3.Recordset.EOF
Key1 = "A" & Adodc3.Recordset.Fields("编号")
str2 = Adodc3.Recordset.Fields("专业")
Set node2 = TreeView1.Nodes.Add(node1.Key, tvwChild, Key1, str2, 2)
Adodc4.RecordSource = "select * from banjixinxi where 专业='" + Trim(Adodc3.Recordset.Fields("专业")) + "'and 毕业时间>'" + str(DTPicker1.Value) + "'"
Adodc4.CommandType = adCmdUnknown
Adodc4.Refresh
If Adodc4.Recordset.RecordCount > 0 Then
Adodc4.Recordset.MoveFirst
Do While Not Adodc4.Recordset.EOF
Key2 = "A" & Adodc4.Recordset.Fields("班级编号")
str3 = Adodc4.Recordset.Fields("班级")
Set node3 = TreeView1.Nodes.Add(node2.Key, tvwChild, Key2, str3, 3)
Adodc4.Recordset.MoveNext
Loop
End If
Adodc3.Recordset.MoveNext
Loop
End If
Adodc2.Recordset.MoveNext
Loop
End If
End Sub
Private Sub treeview1_nodeclick(ByVal node As MSComctlLib.node)
Comm1.Enabled = False
If node.Image = 3 Then
List1.Clear
List2.Clear
cname = Trim(node3.Text)
pname = Trim(node2.Text)
rname = Trim(node1.Text)
If Trim(Text3.Text) <> "" And Trim(DataCombo1.Text) <> "" Then
Adodc6.RecordSource = "select * from kechengshezhi where 系别='" + rname + "'and 专业='" + pname + "'and 开课学年='" + Trim(Text3.Text) + "'and 开课学期='" + Trim(DataCombo1.Text) + "'"
Adodc6.CommandType = adCmdUnknown
Adodc6.Refresh
If Adodc6.Recordset.RecordCount > 0 Then
Adodc6.Recordset.MoveFirst
Do While Not Adodc6.Recordset.EOF
List1.AddItem (Adodc6.Recordset.Fields("课程名称"))
Adodc6.Recordset.MoveNext
Loop
End If
Else
MsgBox "请先选择学年和学期", vbOKOnly, "信息提示"
End If
Adodc5.RecordSource = "select * from xueshengjibenxinxi where 系别='" + rname + "'and 专业='" + pname + "'and 班级='" + cname + "'order by 学号"
Adodc5.CommandType = adCmdUnknown
Adodc5.Refresh
If Adodc5.Recordset.RecordCount > 0 Then
Adodc5.Recordset.MoveFirst
Do While Not Adodc5.Recordset.EOF
List2.AddItem (Adodc5.Recordset.Fields("姓名"))
Adodc5.Recordset.MoveNext
Loop
End If
End If
End Sub
多谢
Private Sub Form_Load()
DTPicker1.Value = Date
TreeView1.ImageList = ImageList1
TreeView1.LineStyle = 1
TreeView1.Style = 7
Adodc2.RecordSource = "select * from xibu"
Adodc2.CommandType = adCmdUnknown
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF
Key = "A" & Adodc2.Recordset.Fields("编号")
str1 = Adodc2.Recordset.Fields("系部")
Set node1 = TreeView1.Nodes.Add(, , Key, str1, 1)
Adodc3.RecordSource = "select * from zhuanye where 系别='" + Trim(Adodc2.Recordset.Fields("系部")) + "'"
Adodc3.CommandType = adCmdUnknown
Adodc3.Refresh
If Adodc3.Recordset.RecordCount > 0 Then
Adodc3.Recordset.MoveFirst
Do While Not Adodc3.Recordset.EOF
Key1 = "A" & Adodc3.Recordset.Fields("编号")
str2 = Adodc3.Recordset.Fields("专业")
Set node2 = TreeView1.Nodes.Add(node1.Key, tvwChild, Key1, str2, 2)
Adodc4.RecordSource = "select * from banjixinxi where 专业='" + Trim(Adodc3.Recordset.Fields("专业")) + "'and 毕业时间>'" + str(DTPicker1.Value) + "'"
Adodc4.CommandType = adCmdUnknown
Adodc4.Refresh
If Adodc4.Recordset.RecordCount > 0 Then
Adodc4.Recordset.MoveFirst
Do While Not Adodc4.Recordset.EOF
Key2 = "A" & Adodc4.Recordset.Fields("班级编号")
str3 = Adodc4.Recordset.Fields("班级")
Set node3 = TreeView1.Nodes.Add(node2.Key, tvwChild, Key2, str3, 3)
Adodc4.Recordset.MoveNext
Loop
End If
Adodc3.Recordset.MoveNext
Loop
End If
Adodc2.Recordset.MoveNext
Loop
End If
End Sub
Private Sub treeview1_nodeclick(ByVal node As MSComctlLib.node)
Comm1.Enabled = False
If node.Image = 3 Then
List1.Clear
List2.Clear
cname = Trim(node3.Text)
pname = Trim(node2.Text)
rname = Trim(node1.Text)
If Trim(Text3.Text) <> "" And Trim(DataCombo1.Text) <> "" Then
Adodc6.RecordSource = "select * from kechengshezhi where 系别='" + rname + "'and 专业='" + pname + "'and 开课学年='" + Trim(Text3.Text) + "'and 开课学期='" + Trim(DataCombo1.Text) + "'"
Adodc6.CommandType = adCmdUnknown
Adodc6.Refresh
If Adodc6.Recordset.RecordCount > 0 Then
Adodc6.Recordset.MoveFirst
Do While Not Adodc6.Recordset.EOF
List1.AddItem (Adodc6.Recordset.Fields("课程名称"))
Adodc6.Recordset.MoveNext
Loop
End If
Else
MsgBox "请先选择学年和学期", vbOKOnly, "信息提示"
End If
Adodc5.RecordSource = "select * from xueshengjibenxinxi where 系别='" + rname + "'and 专业='" + pname + "'and 班级='" + cname + "'order by 学号"
Adodc5.CommandType = adCmdUnknown
Adodc5.Refresh
If Adodc5.Recordset.RecordCount > 0 Then
Adodc5.Recordset.MoveFirst
Do While Not Adodc5.Recordset.EOF
List2.AddItem (Adodc5.Recordset.Fields("姓名"))
Adodc5.Recordset.MoveNext
Loop
End If
End If
End Sub
多谢
treeview1_nodeclick() 刷新 List1、List2 的查询条件与当前选择的节点毫无关系,如果我没猜错的话,应该是
cname = Trim(node.Text)
pname = Trim(node.parent.Text)
rname = Trim(node.parent.parent.Text)