C# Datagrid-如何更改整行的颜色?

C# Datagrid-如何更改整行的颜色?,c#,datagrid,colors,C#,Datagrid,Colors,我有一个包含datagrid的windows窗体。 目前,我有一个事件“dataGrid_CellFormatting”,它检查单元格的内容是否包含单词FAIL,并将此单元格的颜色更改为红色。这很有效。 我必须更改什么,使整行变为红色,而只有单元格 Thx 为什么不只是更改行中的所有单元格 private void dataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dat

我有一个包含datagrid的windows窗体。 目前,我有一个事件“dataGrid_CellFormatting”,它检查单元格的内容是否包含单词FAIL,并将此单元格的颜色更改为红色。这很有效。 我必须更改什么,使整行变为红色,而只有单元格

Thx


为什么不只是更改行中的所有单元格

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;
            }   
        }
    }
}
可能重复的
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;
            }   
        }
    }
}