|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using an image in a datagrid column header..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/browse_thread/thread/53845e1dbd97e466/e160bae0395ccf9b?lnk=st&q=.net+grid+image+instead+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. 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 Show quoteHide quote On Feb 13, 5:08 pm, "ClayB" <c***@syncfusion.com> wrote: > 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. 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] Show quoteHide quote On Feb 13, 5:08 pm, "ClayB" <c***@syncfusion.com> wrote: > 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. The code provided does do it for the header.
Show quoteHide quote "modi321" wrote: > 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] > > > On Feb 13, 5:08 pm, "ClayB" <c***@syncfusion.com> wrote: > > 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. > > >
Other interesting topics
.NET C# Winforms question about window opening
TypeConverter question GroupBox and/or Tab Control Font Colours how to tell if notifyicon hooked ok arrow keys Resize nested control at runtime A Label control that its text can be selected with the mouse Need help on some PropertyGrid and PropertyGridView members Displaying a status image in a datagridview Setting a style for a selected row in the DataGridView |
|||||||||||||||||||||||