I'm using the CellPainting event to customize how the cells are painted.
But when I use the DataGridViewCellPaintingEventArgs passed in, and call the
PaintContent method, it seems to ignore the Rectangle that I pass in. It
just paints the text in the same place everytime. Any ideas?
Override the OnPaint event handler of the cell itself. This will require
creating an inherited cell class.

Signature
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Show me your certification without works,
and I'll show my certification
*by* my works.
> I'm using the CellPainting event to customize how the cells are painted.
> But when I use the DataGridViewCellPaintingEventArgs passed in, and call
> the PaintContent method, it seems to ignore the Rectangle that I pass in.
> It just paints the text in the same place everytime. Any ideas?
> I'm using the CellPainting event to customize how the cells are painted.
> But when I use the DataGridViewCellPaintingEventArgs passed in, and call the
> PaintContent method, it seems to ignore the Rectangle that I pass in. It
> just paints the text in the same place everytime. Any ideas?
Hi Greg,
I recent discovered this same problem. If you don't mind using
reflection to hack the DataGridViewCellPaintingEventArgs class a little
you can try my work around (in C#)...
Object[] args = new Object[12] ;
args[0] = e.Graphics;
args[1] = e.ClipBounds;
args[2] = headerRect; // your modified rectangle, passed as the
// cellBounds
args[3] = e.RowIndex;
args[4] = e.ColumnIndex;
args[5] = e.State;
args[6] = e.Value;
args[7] = e.FormattedValue;
args[8] = e.ErrorText;
args[9] = e.CellStyle;
args[10] = e.AdvancedBorderStyle;
args[11] = e.PaintParts;
e.GetType().InvokeMember("SetProperties",
BindingFlags.Instance |
BindingFlags.InvokeMethod |
BindingFlags.NonPublic,
null, e, args);
HTHS
Kevin Spencer - 30 Mar 2006 18:15 GMT
Here's an example from MSDN2:
http://msdn2.microsoft.com/en-US/library/system.windows.forms.datagridview.cellp
ainting.aspx

Signature
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Show me your certification without works,
and I'll show my certification
*by* my works.
>> I'm using the CellPainting event to customize how the cells are painted.
>> But when I use the DataGridViewCellPaintingEventArgs passed in, and call
[quoted text clipped - 31 lines]
>
> HTHS
johneevo - 30 Mar 2006 20:27 GMT
> Here's an example from MSDN2:
>
> http://msdn2.microsoft.com/en-US/library/system.windows.forms.datagridview.cellp
ainting.aspx
Hi Kevin,
Yes I did see that in the Help.
But I also want to be able to support VisualStyles. I was able to use
the VisualStyleRender to do this up to the point of getting the
SortArrow to draw. I just could get that to work.
I tried to create a VisualStyleRender using the SortArrow StyleElement
(see code below) and just kept getting the error: "Given combination of
Class, Part, and State is not defined by the current visual style." So
I finally gave up and decided to try to get Dot Net to draw it for me
while respecting the limits of my rectangle.
Here's the code snippet
VisualStyleRenderer vsr = new VisualStyleRenderer(
VisualStyleElement.Header.SortArrow.SortedDown);
Kevin Spencer - 31 Mar 2006 13:59 GMT
Wish I could help you more, but honestly, I haven't played with this
particular item (VisualStyleElement and VisualStyleRenderer).

Signature
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Show me your certification without works,
and I'll show my certification
*by* my works.
>> Here's an example from MSDN2:
>>
[quoted text clipped - 16 lines]
> VisualStyleRenderer vsr = new VisualStyleRenderer(
> VisualStyleElement.Header.SortArrow.SortedDown);
johneevo - 31 Mar 2006 14:58 GMT
> Wish I could help you more, but honestly, I haven't played with this
> particular item (VisualStyleElement and VisualStyleRenderer).
That's OK. Using the reflection trick is working for the most part just
need to use some more hacks to get the column header to display "Hot" or
not as appropriate.
The real reason for my post was more to try to help Greg out if he
didn't get his stuff working yet.
Thanks again.