DataGridView
内容に基づいて行の色を変更するために CellFormatting メソッドを使用している で問題が発生しています。DGV の最初の行が true を返すまで、ほとんどの場合、これは正常に機能するようです。この場合、DGV のすべての行が赤色になります。
これが私のコードです:
private void MyData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow theRow = MyData.Rows[e.RowIndex];
if (theRow.Cells[4].Value.ToString() == "1")
{
ChangeRowColor(theRow, Color.PaleVioletRed);
}
}
private void ChangeRowColor(DataGridViewRow r, Color c)
{
r.DefaultCellStyle.BackColor = c;
}
編集:解決策:
private void MyData_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow theRow = MyData.Rows[e.RowIndex];
if ((int)theRow.Cells[4].Value == 1)
{
e.CellStyle.BackColor = Color.PaleVioletRed;
}
}