我畫在這樣一個DataGridView我行太慢:C#的WinForms DataGridView的背景顏色渲染
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;
}
}
}
然後我把它在onload方法:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AdjustColors();
}
我喜歡的OnLoad到OnPaint或其他...因爲OnPaint經常被調用。
的問題:爲什麼要過大約100 - 200 ms來改變每一行的背景是什麼? 早期,我doint CellPaint ..但我刷新時滾動時遇到問題..
你的意思是每行需要100 - 200ms?這聽起來很重。 – leppie
多少行?你在表單上有雙緩衝設置嗎?你有沒有嘗試過使用CellFormatting事件? – stuartd