PC Review


Reply
Thread Tools Rate Thread

Custom DataGridViewTextBoxCell refreshing...

 
 
Kevin
Guest
Posts: n/a
 
      11th Feb 2007
I've created a custom class that inherits from the
DataGridViewTextBoxColumn and DataGridViewTextBoxCell. The cell is
databound to a text field that contains the path to a JPG image. The
JPG image is displayed in the cell if the picture is present on the
harddrive using Protected Overloads Overrides Sub Paint.

The problem is that the image is only displayed in the cell when the
cell receives the focus.

How can I get it to paint the picture in each visible row without the
row receiving focus first?
 
Reply With Quote
 
 
 
 
ClayB
Guest
Posts: n/a
 
      11th Feb 2007
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
Syncfusion, Inc.

 
Reply With Quote
 
Kevin
Guest
Posts: n/a
 
      11th Feb 2007
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




On 11 Feb 2007 01:12:43 -0800, "ClayB" <(E-Mail Removed)> 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
>Syncfusion, Inc.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridViewTextBoxCell force selectall Fre Microsoft Dot NET Framework Forms 0 6th Sep 2008 10:17 PM
Overriding DataGridViewTextBoxCell ReadOnly J.Macek Microsoft Dot NET Framework Forms 0 12th Sep 2007 03:13 PM
DataGridViewTextBoxCell and binding =?Utf-8?B?cmZ3Njg=?= Microsoft Dot NET Framework 5 19th May 2006 10:31 AM
Cut/Copy/Paste in DataGridViewTextBoxCell =?Utf-8?B?TmF0aGFu?= Microsoft C# .NET 0 4th Apr 2006 09:20 PM
Cut/Copy/Paste in DataGridViewTextBoxCell =?Utf-8?B?TmF0aGFu?= Microsoft VB .NET 0 4th Apr 2006 09:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:57 AM.