I was using a Property called Image that would retrieve the image from
the file and for some reason the rowvalue wasn't being passed to it. I
got rid of it altogether and retrieve the image in the Paint sub.
I put the image into a picturebox the size I need the image to be and
then I pass the picturebox image. Thanks for your reply. You made me
rethink my code a little bit. Here's what I'm using:
Protected Overloads Overrides Sub Paint(ByVal graphics As Graphics,
ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal
rowIndex As Integer, ByVal cellState As DataGridViewElementStates,
ByVal value As Object, ByVal formattedValue As Object, ByVal errorText
As String, ByVal cellStyle As DataGridViewCellStyle, ByVal
advancedBorderStyle As DataGridViewAdvancedBorderStyle, ByVal
paintParts As DataGridViewPaintParts)
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex,
cellState, value, formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts)
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex,
cellState, value, formattedValue, _
errorText, cellStyle, advancedBorderStyle, paintParts)
Dim pt As Point = cellBounds.Location
Try
Dim OriginalImage As Image =
Image.FromFile(My.Settings.ImagePath + "\" + value)
Dim SmallerImage As New Bitmap(OriginalImage,
PictureBox1.Width, PictureBox1.Height)
PictureBox1.Image = SmallerImage
graphics.DrawImage(PictureBox1.Image, cellBounds.Location)
Catch
'do nothing
End Try
End Sub
[quoted text, click to view] On 11 Feb 2007 01:12:43 -0800, "ClayB" <clayb@syncfusion.com> wrote:
>Here is a custom cell class that worked ok for me to show a 10x10
>bitmap in a particular column in each row. Do the bitmaps you use fit
>into the cell?
>
>Public Class MyTextBoxCell
> Inherits DataGridViewTextBoxCell
>
> Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal
>clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex
>As Integer, ByVal cellState As DataGridViewElementStates, ByVal value
>As Object, ByVal formattedValue As Object, ByVal errorText As String,
>ByVal cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As
>DataGridViewAdvancedBorderStyle, ByVal paintParts As
>DataGridViewPaintParts)
> MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex,
>cellState, value, formattedValue, errorText, cellStyle,
>advancedBorderStyle, paintParts)
> Dim pt As Point = cellBounds.Location
> pt.Offset(2, 2)
> graphics.DrawImage(Bitmap.FromFile("Bitmap1.bmp"), pt)
> End Sub 'Paint
>End Class 'MyTextBoxCell
>
>================
>Clay Burch