C# 在C语言中为dataGridView单元格提供背景图像#

C# 在C语言中为dataGridView单元格提供背景图像#,c#,datagridview,cell,background-image,C#,Datagridview,Cell,Background Image,我想使用.net组件DataGridView为行标题和列标题提供一个来自图像的自定义背景。甚至可以这样做吗?如果是,怎么做 我使用Visual Studio 2008、windows应用程序、C#。可以更改datagridview行标题的属性。您需要处理CellPaint或RowPostPaint事件,并在行标题单元格中手动绘制图像 protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)

我想使用.net组件DataGridView为行标题和列标题提供一个来自图像的自定义背景。甚至可以这样做吗?如果是,怎么做


我使用Visual Studio 2008、windows应用程序、C#。

可以更改datagridview行标题的属性。您需要处理CellPaint或RowPostPaint事件,并在行标题单元格中手动绘制图像

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

这样做的方法是在RowDataBound事件中为每个头元素添加一个cssClass名称,如下所示,并在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:


我仍然不知道这段代码如何帮助我实现这一点。我确实尝试覆盖RowPostPaint事件,但我仍然不知道如何使用它为未来的Google用户插入单元格背景的图像:同样的技巧也可以用于单元格,为您的单元格提供渐变背景(使用
LinearGradientBrush
),仅使用OnRowPrePaint,并将单元格的默认背景色设置为透明,我如何定义css本身。是否应该是外部文件?正确的方法是包含对外部样式表的引用,但您可以在页面上内联包含样式。这是针对ASP.net的,而不是WinForms。在回答之前,请阅读标记。。。Pieter888正在询问wor winforms,您的答案是ASP.net
.bgimage{ background-image:url(images/arrow-red-large-down.gif);