一、之前,表不多、图片列也少,所以在两三个表的 DrawCell 事件中,加上了下面这段代码,一直使用正常:
Select Case e.Col.Name
Case "联系人照片"
e.StartDraw
If e.Row("联系人照片") > "" Then
Dim Ls = e.Row.DataRow.Lines("联系人照片")
If FileSys.FileExists(projectPath & "RemoteFiles\" & Ls(0)) Then '如果文件存在
e.Graphics.DrawImage(getimage(projectPath & "RemoteFiles\" & Ls(0)), e.x + 5,e.y + 5, 90, 75) ' 绘制第一个图标
End If
End If
e.text = ""
e.EndDraw
Case "产品图片"
e.StartDraw
If e.Row("产品图片") > "" Then
Dim Ls = e.Row.DataRow.Lines("产品图片")
If FileSys.FileExists(projectPath & "RemoteFiles\" & Ls(0)) Then '如果文件存在
e.Graphics.DrawImage(getimage(projectPath & "RemoteFiles\" & Ls(0)), e.x + 5,e.y + 5, 100, 75) ' 绘制第一个图片
End If
End If
e.text = ""
e.EndDraw
End Select
二、现在,表、图片列都多了,所以取消了在各个表中的代码,统一在全局表事件 DrawCell 中,加上了下面的代码。
但是不执行,什么原因呢?
For Each dc As DataCol In e.Table.DataTable.DataCols
If dc.ExtendType = ExtendTypeEnum.Images Then
e.StartDraw
If e.Row(dc.Name) > "" Then
Dim Ls = e.Row.DataRow.Lines(dc.Name)
If FileSys.FileExists(projectPath & "RemoteFiles\" & Ls(0)) Then ' 如果文件存在
Dim strs As String = dc.Name
If strs.Contains("照片") Then
e.Graphics.DrawImage(getimage(projectPath & "RemoteFiles\" & Ls(0)), e.x + 5,e.y + 5, 90, 75) ' 绘制第一个图标
ElseIf strs.Contains("图片") Then
e.Graphics.DrawImage(getimage(projectPath & "RemoteFiles\" & Ls(0)), e.x + 5,e.y + 5, 100, 75) ' 绘制第一个图标
End If
End If
End If
e.text = ""
e.EndDraw
End If
Next
【说明】之前没有加 Dim strs As String = dc.Name,直接使用的 dc.Name
因为代码不执行,才加了 strs 进行测试。