Dim enterDate As DateTime = e.Form.Control.("DateTimePicker1").Value '获取DateTimePicker2的日期
Dim leaveDate As DateTime = e.Form.Control.("DateTimePicker2").Value '获取DateTimePicker1的日期
Dim lvw As WinForm.ListView = e.Form.Controls("ListView1")
lvw.StopRedraw() '停止绘制
lvw.Groups.Clear() '清除原来的分组
lvw.Columns.Clear() '清除原来的列
lvw.Rows.Clear() '清除原来的行
lvw.Images.Clear() '清除原来的图片
lvw.View = ViewMode.Details '显示模式为详细信息
lvw.Images.AddSmallImage("Man", "Man.ico") '添加代表男性的图标
lvw.Images.AddSmallImage("Woman", "Woman.ico") '添加代表女性的图标
Dim cls() As String = {"姓名", "性别", "出生日期", "年龄", "身份证号码", "现聘岗位", "现聘职务", "政治面貌", "进入单位日期", "籍贯", "民族", "婚姻状况", "毕业院校", "所学专业", "离开单位日期", "联系电话", "人员状态"} '定义列名
For i As Integer = 0 To cls.Length - 1'增加列
Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
c.Name = cls(i) '指定列名
c.Text = cls(i) '指定标题,这里标题和列名相同
c.TextAlign = HorizontalAlignment.Center
Next
For Each lb As String In DataTables("EI").GetValues("人员类别") '增加分组
Dim grp As WinForm.ListViewGroup = lvw.Groups.Add()
grp.Name = lb
grp.Text = lb
Next
Dim filteredDRs As DataRow() = DataTables("EI").Select("进入单位日期 < #" & enterDate & "# OR 离开单位日期 > #" & leaveDate & "#") '筛选数据行
For Each dr As DataRow In filteredDRs
Dim r As WinForm.ListViewRow = lvw.Rows.Add() '增加一行
r.Group = dr("人员类别") '指定所属分组
For Each cl As String In cls '逐列取值
r(cl) = dr(cl)
Next
If dr("性别") = "男" Then '设置分组
r.ImageKey = "Man"
Else
r.ImageKey = "Woman"
End If
r.Tag = dr'将DataRow赋值给ListViewRow的Tag属性,将二者联系起来
Next
lvw.ResumeRedraw() '恢复绘制