事件过程代码如下。
Private Sub Form_Load()
Dim key As String, Text As String, key1 As String, Text1 As String
Dim nod As Node
Dim str As String, DataSource As String
Height = 7180
Width = 11800
Top = 0
Left = 0
Rs_TB06.Open 'TB06', Con, adOpenKeyset, adLockPessimistic '打开TB06表
If Rs_TB06.RecordCount > 0 Then '判断TB06表中有系部记录
With Rs_TB06
Do While Not .EOF
key = .Fields('TB0602') '将TB0602(系部名称)字段设置为要添加结点的关键字
Text = .Fields('TB0602') '将TB0602(系部名称)字段设置为要添加结点的文本
str = .Fields('TB0601') '将TB0601(系部编码)字段保存在str中
Set nod = TreeView_TB03.Nodes.Add(, tvwChild, key, Text) '将系部名称添加到树形控件上
DataSource = 'Select * from TB03 where TB0309='' & str & ''' '该查询语句实现根据系部选班级
Rs_TB03.Open DataSource, Con, adOpenKeyset, adLockPessimistic '将该系部下的班级记录打开
With Rs_TB03
Do While Not .EOF
key1 = .Fields('tb0302') '将TB0302(班级名称)字段设置为要添加结点的关键字
Text1 = .Fields('tb0302') '将TB0302(班级名称)字段设置为要添加结点的文本
'以上面系部名称结点为父结点,添加该系下的班级名称结点
Set nod = TreeView_TB03.Nodes.Add(key, tvwChild, key1, Text1)
.MoveNext '添加下一个班级
Loop
.Close
End With
.MoveNext'添加下一个系部
Loop
.Close
End With
End If
End Sub
(3)编写单击树形控件中班级节点,查询该班所有学生信息的事件过程
Private Sub TreeView_TB03_NodeClick(ByVal Node As MSComctlLib.Node)
Dim I As Integer, Sum1 As Integer, Sum2 As Integer, BJ As String
With Adodc_XA01
BJ = TreeView_TB03.SelectedItem.Text '获得树形控件所选择的结点的文本,即班级名称
.CommandType = adCmdText
.RecordSource = 'Select A.*,GC0102,GC0202,GC0302,GC0402,TB0302 ' & _
'From XA01 As A ,GC01,GC02,GC03,GC04 ,TB03 ' & _
'Where XA0106 = GC0101 And XA0108 = GC0301 And XA0109 = GC0201 and XA0110=GC0401 ' & _
'and XA0114=TB0301 and TB0302='' & BJ & ''' '通过该条查询语句查询出该班级的学生信息
.Refresh
End With
DataGrid_XA01.Refresh '在DataGrid控件上显示最新的记录
With Adodc_XA01.Recordset
If Not .BOF Then .MoveFirst
Do While Not .EOF '访问所选择出来的每一条学生记录
If .Fields('XA0106').Value = '1' Then Sum1 = Sum1 1 '如果是男生,则男生人数加1
If .Fields('XA0106').Value = '2' Then Sum2 = Sum2 1 '如果是女生,则女生人数加1
.MoveNext
Loop
If Not .BOF Then .MoveFirst
End With
StatusBar1.Panels(2).Text = '男生人数:' & Sum1 '在状态栏上显示男生人数
StatusBar1.Panels(3).Text = '女生人数:' & Sum2 '在状态栏上显示女生人数
StatusBar1.Panels(4).Text = '合计人数:' & Sum1 Sum2 '在状态栏上显示总人数
End Sub
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。