Tôi vẽ hàng của tôi trong một DataGridView như thế này:C màu nền # WinForms DataGridView render quá chậm
private void AdjustColors()
{
foreach (DataGridViewRow row in aufgabenDataGridView.Rows)
{
AufgabeStatus status = (AufgabeStatus)Enum.Parse(typeof(AufgabeStatus), (string)row.Cells["StatusColumn"].Value);
switch (status)
{
case (AufgabeStatus.NotStarted):
row.DefaultCellStyle.BackColor = Color.LightCyan;
break;
case (AufgabeStatus.InProgress):
row.DefaultCellStyle.BackColor = Color.LemonChiffon;
break;
case (AufgabeStatus.Completed):
row.DefaultCellStyle.BackColor = Color.PaleGreen;
break;
case (AufgabeStatus.Deferred):
row.DefaultCellStyle.BackColor = Color.LightPink;
break;
default:
row.DefaultCellStyle.BackColor = Color.White;
break;
}
}
}
Sau đó, tôi gọi nó là trong phương pháp onload:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AdjustColors();
}
tôi thích onload để OnPaint hoặc một cái gì đó .. bởi vì OnPaint được gọi rất thường xuyên.
Câu hỏi: Tại sao phải mất khoảng 100 - 200 mili giây để thay đổi nền của mỗi hàng? Sớm, tôi là doint CellPaint .. nhưng tôi gặp sự cố khi cuộn bằng làm mới ..
Bạn có nghĩa là phải mất 100 - 200ms mỗi hàng? Nghe có vẻ khá nặng. – leppie
Có bao nhiêu hàng? Bạn có đặt bộ đệm đôi trên biểu mẫu không? Bạn đã thử sử dụng sự kiện CellFormatting chưa? – stuartd