Using an image in a datagrid column header..

  • Thread starter Thread starter modi321
  • Start date Start date
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.
 
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
 
Back
Top