【发布时间】:2009-10-27 11:00:07
【问题描述】:
我正在像这样在 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 毫秒? 早期,我在使用 CellPaint.. 但是在刷新滚动时遇到问题..
【问题讨论】:
-
您的意思是每行需要 100 - 200 毫秒?听起来很沉重。
-
多少行?您是否在表单上设置了双缓冲?您是否尝试过使用 CellFormatting 事件?
标签: c# winforms datagridview