代码之家  ›  专栏  ›  技术社区  ›  Pieter888

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

  •  3
  • Pieter888  · 技术社区  · 16 年前

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

    2 回复  |  直到 16 年前
        1
  •  2
  •   Webking    16 年前

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

     protected override void  OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
            {
                 // Your code to insert image/content per cell goes here    
            }
    
        2
  •  -2
  •   user209875 user209875    16 年前

    这样做的方法是在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:

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