[英]Datagrid - how to change color of complete row?
i have a windows-form that contains a datagrid. 我有一个包含数据网格的Windows窗体。 Currently i have the event "dataGrid_CellFormatting" that checks if the content of a cell contains the word FAIL and the changes the color of this cell to red.
目前,我有事件“ dataGrid_CellFormatting”,该事件检查单元格的内容是否包含单词FAIL,并将该单元格的颜色更改为红色。 This works.
这可行。 What do i have to change that the complete row is changed to red and only the cell?
我必须更改将整个行更改为红色并且仅将单元格更改为什么?
Thx 谢谢
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;
}
}
}
Any reason why you are not just changing all the cells in the row? 您为什么不只是更改行中的所有单元格有什么原因吗?
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.