How To Insert Image To DataGridView Column Header

Hi All,

I wonder if it's possible to insert an image to a DataGridView Column Header.

Tanks In Advance

Boaz Shalev.

 



Answer this question

How To Insert Image To DataGridView Column Header

  • Hong Ju Zhang

    Is their any solution without overriden the DataGridView something like the pre and post paint events that each row sends



  • Troy Neville

    There isn't any Image property or such, but you can handle the CellPainting event and add the image to the column header. The RowIndex for the paint event will be -1 for column headers.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

     

    -mark

    DataGridView Program Manager

    Microsoft

    This post is provided "as-is"-mark

     

     


  • Ben Pryor

    Totally -- you can handle the CellPainting event and do this -- doesn't require overriding the DataGridView.

    -mark

    DataGridView Program Manager

    Microsoft

    This post is provided "as-is"


  • madhatt30

    Hi Mark,

    Can you send me code sample

    Thanks

    Boaz Shalev.


  • jbourne

    Hi
    Thanks a lot but ... i already knew that a even replied to that post ...
    Regards


  • bstsms

    Hi.


    Can anyone tell how can i add an image to the rowHeader Column of a datagridview

    Help would be appreciated


    Regards




  • JonL.

    Hi, There is a similar post for writing the image on RowHeader... pls refer..
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=51557&SiteID=1

    And, follwoing is the code from the post:


    protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
    {
    // must call base event for other implementions
    base.OnRowPostPaint(e);

    // Paint Circle on the rowHeader if needed
    if(_breakPoints.Contains(e.RowIndex))
    {
    // Gets the color to draw the circle with
    Color rowColor = (Color)_breakPoints[e.RowIndex];
    Brush circleColor = new SolidBrush(rowColor);
    // Draw the circle
    e.Graphics.FillEllipse(circleColor, e.RowBounds.Location.X + 20,
    e.RowBounds.Location.Y + 4, 10, 10);
    }

    }

    guess, this will help draw the column header also..

    Regards,

    Vivek


  • How To Insert Image To DataGridView Column Header