내 DataGridView
에서 CellFormatting 메서드를 사용하여 해당 내용을 기반으로 행의 색을 다시 지정하는 데 문제가 있습니다. 이것은 DGV의 첫 번째 행이 true를 반환 할 때까지 대부분의 경우에 잘 작동합니다.이 경우 DGV의 모든 행은 빨간색으로 표시됩니다.C# DataGridView 행 색 지정
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;
}
}
나에게 서식을 지정해 주셔서 감사합니다. newb입니다. – Krisisonfire
else if 절 이후에 else {ChangeRowColor (theRow, Color.White);}'를 추가하면 도움이됩니까? – Pikoh
샘플 데이터를 제공 할 수 있습니까? – Berkay