Hello. I have a datagridview with 5000 entries. And I want to color the rows based on some values. Here's how I do it:
foreach (DataGridViewRow row in rows)
{
var handlingStage = (ESourceHandlingStage)row.Cells["HandlingStage"].Value;
switch (handlingStage)
{
case ESourceHandlingStage.NotStarted:
row.DefaultCellStyle.BackColor = UnhandledColor;
row.DefaultCellStyle.SelectionBackColor = Color.Blue;
break;
case ESourceHandlingStage.Given:
row.DefaultCellStyle.BackColor = GivenColor;
row.DefaultCellStyle.SelectionBackColor = Color.Blue;
break;
case ESourceHandlingStage.Taken:
row.DefaultCellStyle.BackColor = TakenColor;
row.DefaultCellStyle.SelectionBackColor = Color.Blue;
break;
case ESourceHandlingStage.Handled:
row.DefaultCellStyle.BackColor = HandledColor;
row.DefaultCellStyle.SelectionBackColor = Color.Blue;
break;
case ESourceHandlingStage.Loaded:
row.DefaultCellStyle.BackColor = LoadedColor;
row.DefaultCellStyle.SelectionBackColor = Color.Blue;
break;
default:
break;
}
}
But when form loads it freezes for a couple of seconds. Can can I avoid it?
Thank you for your help!