多 CustomUnboundColumnData 图像 gridview devexpress 的性能非常慢,因为每个图像文件的大小约为 600 kb,总图像文件约为 15000。是否有多个 CustomUnboundColumnData 图像 gridview 想要成为缩略图的解决方案?让它变得更快。还是有其他最好的推荐?
谢谢 roykana
Imports Microsoft.VisualBasic
Imports DevExpress.XtraEditors
Imports System
Imports System.Data
Imports System.Linq
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid.Views.Grid
Imports System.Drawing
Imports System.Collections
Namespace Example
Partial Public Class XtraForm1
Inherits XtraForm
Public Sub New()
InitializeComponent()
End Sub
Private Images As Hashtable = New Hashtable()
Private Sub PopulateDataGridView()
gridControl1.DataSource = GetPersonDataTable()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PopulateDataGridView()
Dim repItemGraphicsEdit As New RepositoryItemPictureEdit() 'RepositoryItemGraphicsEdit()
repItemGraphicsEdit.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Squeeze
gridControl1.RepositoryItems.Add(repItemGraphicsEdit)
gridView1.Columns("IMAGE1").ColumnEdit = repItemGraphicsEdit
gridView1.Columns("IMAGE2").ColumnEdit = repItemGraphicsEdit
gridView1.Columns("IMAGE3").ColumnEdit = repItemGraphicsEdit
gridView1.Columns("IMAGE4").ColumnEdit = repItemGraphicsEdit
gridView1.Columns("IMAGE5").ColumnEdit = repItemGraphicsEdit
gridView1.Columns("IMAGE6").ColumnEdit = repItemGraphicsEdit
End Sub
Private Sub gridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles gridView1.CustomUnboundColumnData
Dim view As GridView = TryCast(sender, GridView)
Dim filename1 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME1")) Then
filename1 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME1"))
Else
filename1 = String.Empty 'or Nothing depending what comes next.
End If
Dim filename2 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME2")) Then
filename2 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME2"))
Else
filename2 = String.Empty 'or Nothing depending what comes next.
End If
Dim filename3 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME3")) Then
filename3 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME3"))
Else
filename3 = String.Empty 'or Nothing depending what comes next.
End If
Dim filename4 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME4")) Then
filename4 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME4"))
Else
filename4 = String.Empty 'or Nothing depending what comes next.
End If
Dim filename5 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME5")) Then
filename5 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME5"))
Else
filename5 = String.Empty 'or Nothing depending what comes next.
End If
Dim filename6 As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME6")) Then
filename6 = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "FILENAME6"))
Else
filename6 = String.Empty 'or Nothing depending what comes next.
End If
Dim SUBFOLDERP As String
If Not DBNull.Value.Equals(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "SUBFOLDERP")) Then
SUBFOLDERP = CStr(view.GetListSourceRowCellValue(e.ListSourceRowIndex, "SUBFOLDERP"))
Else
SUBFOLDERP = String.Empty 'or Nothing depending what comes next.
End If
Dim img As Image = Nothing
Try
If e.Column.Caption = "IMAGE1" Then
e.Value = GetImage(filename1)
ElseIf e.Column.Caption = "IMAGE2" Then
e.Value = GetImage(filename2)
ElseIf e.Column.Caption = "IMAGE3" Then
e.Value = GetImage(filename3)
ElseIf e.Column.Caption = "IMAGE4" Then
e.Value = GetImage(filename4)
ElseIf e.Column.Caption = "IMAGE5" Then
e.Value = GetImage(filename5)
ElseIf e.Column.Caption = "IMAGE6" Then
e.Value = GetImage(filename6)
End If
Catch
End Try
End Sub
Function GetImage(str As String) As Image
If (Images.ContainsKey(str)) Then
Return CType(Images(str), Image)
Else
Dim img = Image.FromFile(str)
Images.Add(str, img)
Return img
End If
End Function
Private Function GetPersonDataTable() As DataTable
Dim table As New DataTable()
table.TableName = "Persons"
table.Columns.Add(New DataColumn("FILENAME1", GetType(String)))
table.Columns.Add(New DataColumn("FILENAME2", GetType(String)))
table.Columns.Add(New DataColumn("FILENAME3", GetType(String)))
table.Columns.Add(New DataColumn("FILENAME4", GetType(String)))
table.Columns.Add(New DataColumn("FILENAME5", GetType(String)))
table.Columns.Add(New DataColumn("FILENAME6", GetType(String)))
For i As Integer = 0 To 15000
table.Rows.Add("1.png", "2.png", "3.png", "4.png", "5.png", "6.png")
Next i
Return table
End Function
End Class
End Namespace