473,503 Members | 3,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom DataGridViewTextBoxCell refreshing...

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?
Feb 11 '07 #1
2 3915
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.

Feb 11 '07 #2
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" <cl***@syncfusion.comwrote:
>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.
Feb 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
890
by: Cuperman | last post by:
Does anyone know of an issue where a Configuration Exception is thrown when "Program Files" is used as part of the initialiseData value within a custom listener? eg: <system.diagnostics> <trace...
0
1057
by: Do | last post by:
Hi, I have a datagrid in a custom user control that must be refreshed after I click a button. My custom user control is named dtgDocuments. I can't find any kind of reload method for the...
5
3472
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
0
1359
by: Nathan | last post by:
The textbox has Cut(), Copy(), and Paste() methods that can be called from, say, a menuitem click event. Is there a way to get a DataGridViewTextBoxCell to do the same thing?
1
6543
by: PT | last post by:
Hi, I'm creating a library of basic constol that I often use, and am just getting to the whole custom process, I've started by creating something simple by inheriting from a textbox, I have two...
0
2116
by: Alex Brown | last post by:
Is it a problem to attach Non-static site map providers under one that inherits from StaticSiteMapProvider ? We are implementing a custom site map provider for a website that is being converted...
1
3509
by: Charles Bazi | last post by:
Hi, Based on MSDN http://msdn2.microsoft.com/en-us/library/7tas5c80.aspx smple, I have made my custom DataGridViewColumn. I use it to host a custom control, sort of ComboBox, but instead of...
1
2487
by: lbelkova | last post by:
Hello, I've created a custom DataGridViewColumn. Everything work well, except for some reason the column doesn't accept some of the chars: "q", "." and "'". Did anybody have a similar problem?...
2
2894
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I have some information I want to put into a dataGridViewTextBoxCell, but I don't want it all on one line. The information is being put in programmatically, so no use input for it. I've tried the...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.