认真看看2楼的回复呗:如果说ListView要2次才能显示符号条件的行倒是会,因为先添加ListView数据再加载的数据
如果是指窗口的ListView新时代额数据有问题,应该先加载员工表格的数据,再去生成ListView
方法1:不能用
方法2:没有问题
Dim Filter As String
With e.Form.Controls("地区")
If .Value IsNot Nothing Then
Filter = "地区 = '" & .Value & "'"
End If
End With
With e.Form.Controls("部门")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "部门 in ('" & .Value.replace(",", "','") & "')"
End If
End With
With e.Form.Controls("性别")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "性别 in ('" & .Value.replace(",", "','") & "')"
End If
End With
If Filter > "" Then
DataTables("员工").loadFilter = Filter
DataTables("员工").load
End If
Dim lvw As WinForm.ListView = e.Form.Controls("ListView1")
lvw.StopRedraw() '暂停绘制
lvw.Rows.Clear() '清除原来的行
lvw.Images.Clear() '清除原来的图片
lvw.View = ViewMode.Tile '显示模式为平铺
lvw.Images.LargeSize = New Size(65, 75) '定义大图标尺寸
lvw.TitleSize = New Size(150, 90) '设置平铺区域的大小
Dim cls() As String = {"姓名", "空行1", "部门", "空行2", "地区", "性别"} '定义列名
For i As Integer = 0 To cls.Length - 1 '增加列
Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
c.Name = cls(i) '指定列名
Next
For Each dr As DataRow In DataTables("员工").DataRows '从数据表中提取数据
Dim Key As String = dr("照片")'获取此员工的照片文件
lvw.Images.AddLargeImage(Key, Key) '添加照片,直接用文件名作为图片键值
Dim vr As WinForm.ListViewRow = lvw.Rows.Add() '增加一行
vr.ToolTipText = dr("编号") '设置此行的动态提示
vr.ImageKey = Key '设置图片键值
vr.Group = dr("地区") '指定所属分组
vr("姓名") = dr("姓名")
vr("空行1") = " "
vr("部门") = "部门:" & dr("部门")
vr("空行2") = " "
vr("地区") = "地区:" & dr("地区")
vr("性别") = "性别:" & dr("性别")
Next
lvw.ResumeRedraw() '恢复绘制
方法3:也没有问题
Dim Filter As String
With e.Form.Controls("地区")
If .Value IsNot Nothing Then
Filter = "地区 = '" & .Value & "'"
End If
End With
With e.Form.Controls("部门")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "部门 = '" & .Value & "'"
End If
End With
With e.Form.Controls("性别")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "性别 = '" & .Value & "'"
End If
End With
If Filter > "" Then
DataTables("员工").loadFilter = Filter
DataTables("员工").load
End If
Dim lvw As WinForm.ListView = e.Form.Controls("ListView1")
lvw.StopRedraw() '暂停绘制
lvw.Rows.Clear() '清除原来的行
lvw.Images.Clear() '清除原来的图片
lvw.View = ViewMode.Tile '显示模式为平铺
lvw.Images.LargeSize = New Size(65, 75) '定义大图标尺寸
lvw.TitleSize = New Size(150, 90) '设置平铺区域的大小
Dim cls() As String = {"姓名", "空行1", "部门", "空行2", "地区", "性别"} '定义列名
For i As Integer = 0 To cls.Length - 1 '增加列
Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
c.Name = cls(i) '指定列名
Next
For Each dr As DataRow In DataTables("员工").DataRows '从数据表中提取数据
Dim Key As String = dr("照片")'获取此员工的照片文件
lvw.Images.AddLargeImage(Key, Key) '添加照片,直接用文件名作为图片键值
Dim vr As WinForm.ListViewRow = lvw.Rows.Add() '增加一行
vr.ToolTipText = dr("编号") '设置此行的动态提示
vr.ImageKey = Key '设置图片键值
vr.Group = dr("地区") '指定所属分组
vr("姓名") = dr("姓名")
vr("空行1") = " "
vr("部门") = "部门:" & dr("部门")
vr("空行2") = " "
vr("地区") = "地区:" & dr("地区")
vr("性别") = "性别:" & dr("性别")
Next
lvw.ResumeRedraw() '恢复绘制
老师,方法2与方法3哪个好一些?
Select Case e.DataCol.Name
Case "考勤时间汇总"
If e.DataRow.IsNull("考勤时间汇总") = False Then
' Dim ary() As String = e.DataRow("考勤时间汇总").split(",")
' For Each str As String In ary
For Each str As String In e.DataRow("考勤时间汇总").split(",")
Dim d As Date = New Date(1900, 1, 1, str.Split(":")(0), str.Split(":")(1), 0)
Dim fdr As DataRow = DataTables("班段设置").Find("起始时间 <= #" & d & "#", "起始时间 desc")
If fdr IsNot Nothing Then
Dim Idx As Integer = Tables("班段设置").FindRow(fdr)
Dim cname As String = "自动计算_第" & idx + 1 & "段"
Dim temp As Date = CDate(e.DataRow(cname))
temp = New Date(1900, 1, 1, temp.Hour, temp.Minute, 0)
If e.DataRow.IsNull(cname) Then
e.DataRow("自动计算_第" & idx + 1 & "段") = d
End If
Else
End If
Next
End If
End Select
老师,上面这段代码正确,我想加一个判断,请教下面这个代码怎么修改?
Select Case e.DataCol.Name
Case "考勤时间汇总"
If e.DataRow.IsNull("考勤时间汇总") = Nothing Then
e.DataRow("自动计算_第1段") = Nothing
e.DataRow("自动计算_第2段") = Nothing
e.DataRow("自动计算_第3段") = Nothing
e.DataRow("自动计算_第4段") = Nothing
e.DataRow("自动计算_第5段") = Nothing
e.DataRow("自动计算_第6段") = Nothing
Else
For Each str As String In e.DataRow("考勤时间汇总").split(",")
Dim d As Date = New Date(1900, 1, 1, str.Split(":")(0), str.Split(":")(1), 0)
Dim fdr As DataRow = DataTables("班段设置").Find("起始时间 <= #" & d & "#", "起始时间 desc")
If fdr IsNot Nothing Then
Dim Idx As Integer = Tables("班段设置").FindRow(fdr)
Dim cname As String = "自动计算_第" & idx + 1 & "段"
Dim temp As Date = CDate(e.DataRow(cname))
temp = New Date(1900, 1, 1, temp.Hour, temp.Minute, 0)
If e.DataRow.IsNull(cname) Then
e.DataRow("自动计算_第" & idx + 1 & "段") = d
End If
Else
End If
Next
End If
End Select
Select Case e.DataCol.Name
Case "考勤时间汇总"
If e.DataRow.IsNull("考勤时间汇总") Then
e.DataRow("自动计算_第1段") = Nothing