Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

Using an image in a datagrid column header..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
modi321 - 13 Feb 2007 22:36 GMT
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

ClayB - 13 Feb 2007 23:08 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.