Images from file into datagridview

L

LuvinLunch

Hi,

I really appreciate all the help I'm getting from this group.

I'm loading a datagridview and I need to add thumbnails to it based on
a string that's returned from the database. So first I load the data,
then I create and add a datagridviewimagecolumn. The reason I'm
adding a column to show the photo is that the rest of the grid is
bound but the images aren't stored in the database. They're stored on
file.

Then based on a string column returned to the datagrid I loop through
my newly created image column creating a bitmap for each row. I think
creating the bitmap is could be wrong. Anyway, I'm getting a timeout
error. It seems to be able to load about 50 images and then crashes.
Can anyone suggest a better way of loading a number of images from
disk into a datagridviewcolumn please?

LL


Private Sub SetUpPhotos(ByVal iDatagrid As DataGridView)

'Create the column
Dim colPhotos As New DataGridViewImageColumn

'add the images column to the data grid view
colPhotos.Name = "colPhotos"
colPhotos.HeaderText = "Photo"
colPhotos.ImageLayout = DataGridViewImageCellLayout.NotSet
iDataGrid.Columns.Insert(PHOTO_CELL, colPhotos)

'Create a bitmap container
Dim objBMP As New System.Drawing.Bitmap(20, 10)

'Loop through the new column based on other column's field to load
file from disk
Dim imgPath As String
Dim iRowCount As Integer
iRowCount = 0
'set to the column row
For Each row As DataGridViewRow In iDataGrid.Rows
iDataGrid.CurrentCell = iDataGrid(OBJECTID_CELL,
iRowCount)
If Not (IsDBNull(iDataGrid.CurrentCell.Value)) Then
imgPath = GetPathFromObjectID
(iDataGrid.CurrentCell.Value, 4, 1)
If imgPath <> vbNullString Then
iDataGrid.CurrentCell = iDataGrid(PHOTO_CELL,
iRowCount)
'objBMP = New System.Drawing.Bitmap(imgPath)
'iDataGrid(PHOTO_CELL, iRowCount).Value = objBMP
iDataGrid(PHOTO_CELL, iRowCount).Value =
objBMP.FromFile(imgPath)
End If
iRowCount = iRowCount + 1
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top