更改datagridview行中单个单元格的样式

时间:2022-05-01 14:44:46

Is it possible to give individual cells in a data grid view row different styles such as backcolor, fontcolor etc?

是否有可能在数据网格视图行中为单个单元格提供不同的样式,如backcolor,fontcolor等?

I do not mean giving the whole row a new style, only a specific cell.

我并不是说整个行都是一种新的风格,只是一个特定的细胞。

2 个解决方案

#1


certainly:

Me.myDatagridview.Rows(0).Cells(0).Style.ForeColor = Color.Aqua

Me.myDatagridview.Rows(0).Cells(0).Style.ForeColor = Color.Aqua

#2


Something like this?

像这样的东西?

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
      string imageName = e.Row.Cells[0].Text.ToString();
      e.Row.Cells[1].Attributes.Add(“Style”,
        “background-image: url(’images/” + imageName + “‘);”);    
  }
}

#1


certainly:

Me.myDatagridview.Rows(0).Cells(0).Style.ForeColor = Color.Aqua

Me.myDatagridview.Rows(0).Cells(0).Style.ForeColor = Color.Aqua

#2


Something like this?

像这样的东西?

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
      string imageName = e.Row.Cells[0].Text.ToString();
      e.Row.Cells[1].Attributes.Add(“Style”,
        “background-image: url(’images/” + imageName + “‘);”);    
  }
}