I am looking to replace the text of a column header with an image. Is
there any particular trick to do this? The image-column only allows
for images in the actual rows, but I want to substitute a column's
text with an image.
Thanks for the help.
Oh, and I saw this from Feb 2004, and I am not sure if that reflects
the 2.0 framework or any current tricks in the last three years.
http://groups.google.com/group/microsoft.public.dotnet.framework.windowsforms/br
owse_thread/thread/53845e1dbd97e466/e160bae0395ccf9b?lnk=st&q=.net+grid+image+in
stead+of+header&rnum=1&hl=en#e160bae0395ccf9b
One way you can do this is to use the CellsPainting event to draw the
bitmap for a particular header cell. Here is code that does this
assuming the bitmap is in an imagelist.
//this.images is an ImageList with your bitmaps
void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 1 && e.RowIndex == -1)
{
e.PaintBackground(e.ClipBounds, false);
Point pt = e.CellBounds.Location;// where you want the bitmap
in the cell
int offset = (e.CellBounds.Width -
this.images.ImageSize.Width) / 2;
pt.X += offset;
pt.Y += 1;
this.images.Draw(e.Graphics, pt, 0);
e.Handled = true;
}
}
==================
Clay Burch
Syncfusion, Inc.
modi321 - 14 Feb 2007 14:26 GMT
Clay,
Yeah, I was hoping to not this route, but I will investigate.
It seems like if I can drop an image in a cell, then it wouldn't be
too far off to drop an image in a column header. Arg
> One way you can do this is to use the CellsPainting event to draw the
> bitmap for a particular header cell. Here is code that does this
[quoted text clipped - 21 lines]
> Clay Burch
> Syncfusion, Inc.
modi321 - 14 Feb 2007 14:55 GMT
Oh, and I know I can adapt this for the header, but I am not looking
to have it in the cell, but in the caption like this:
[URL=http://img234.imageshack.us/my.php?image=20070214gridka3.jpg]
[IMG]http://img234.imageshack.us/img234/9291/20070214gridka3.th.jpg[/
IMG][/URL]
> One way you can do this is to use the CellsPainting event to draw the
> bitmap for a particular header cell. Here is code that does this
[quoted text clipped - 21 lines]
> Clay Burch
> Syncfusion, Inc.
Ciaran O''Donnell - 15 Feb 2007 15:05 GMT
The code provided does do it for the header.

Signature
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
> Oh, and I know I can adapt this for the header, but I am not looking
> to have it in the cell, but in the caption like this:
[quoted text clipped - 28 lines]
> > Clay Burch
> > Syncfusion, Inc.