giving a dataGridView cell a background image in C#
I want to give the row headers and column headers a custom background from an image using the .net component DataGridView. Is it possible to even do this? And if so, 开发者_JAVA百科how?
I use Visual Studio 2008, windows application, C#.
Its possible to change the attributes of the datagridview rowheader. You'll need to either handle the CellPainting or the RowPostPaint event and manually draw the image in the row header cell.
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
// Your code to insert image/content per cell goes here
}
On way to do this is to put a cssClass name per header element in the RowDataBound event like this and assign your background image in the 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);
精彩评论