Giving the dataGridView cell a background image in C #

I want to give the row headers and column headers their own background from the image using the .net DataGridView component. Is it possible to do this? And if so, how?

I am using Visual Studio 2008, a Windows application, C #.

+3
source share
2 answers

It can change the attributes of a rowheader datagridview. You need to either handle the CellPainting or RowPostPaint event, or manually draw an image in the row header cell.

 protected override void  OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
        {
             // Your code to insert image/content per cell goes here    
        }
+2
source

To do this, put the name cssClass in the header element in the RowDataBound event like this, and assign a background image to css.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell c in e.Row.Cells)
            {
                c.CssClass = "bgimage";
            }
        }
    }

CSS

.bgimage{ background-image:url(images/arrow-red-large-down.gif);
-2

Source: https://habr.com/ru/post/1722685/


All Articles