[英]Datagrid - how to change color of complete row?
我有一个包含数据网格的Windows窗体。 目前,我有事件“ dataGrid_CellFormatting”,该事件检查单元格的内容是否包含单词FAIL,并将该单元格的颜色更改为红色。 这可行。 我必须更改将整个行更改为红色并且仅将单元格更改为什么?
谢谢
private void dataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGrid.Columns[e.ColumnIndex].Name.Equals("cResult"))
{
if ((String)e.Value == "FAIL")
{
e.CellStyle.BackColor = Color.Red;
}
}
}
您为什么不只是更改行中的所有单元格有什么原因吗?
private void dataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGrid.Columns[e.ColumnIndex].Name.Equals("cResult"))
{
if ((String)e.Value == "FAIL")
{
foreach (DataGridViewCell cell in dataGrid.Rows[e.RowIndex].Cells)
{
cell.Style.BackColor = Color.Red;
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.