Имеется код C# Он полностью выполняет свои требования но проблема в том что dataGridView сильно тормозит
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex < 0 || dataGridView1.Rows[e.RowIndex].IsNewRow) return;
var now = DateTime.Now;
var s = Regex.CacheSize;
now = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
if (dataGridView1.Rows[e.RowIndex].Cells["Срок до"].Value != null &&
((DateTime)dataGridView1.Rows[e.RowIndex].Cells["Срок до"].Value).CompareTo(now) < 0)
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
for (var i = 0; i < dataGridView1.Rows.Count; i++)
for (var j = 0; j < dataGridView1.Columns.Count; j++)
{
var formattedValue = dataGridView1.Rows[i].Cells[j].FormattedValue;
if (formattedValue != null && formattedValue.ToString().ToLower() == "удален")
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Gray;
}
}
for (var i = 0; i < dataGridView1.Rows.Count; i++)
for (var j = 0; j < dataGridView1.Columns.Count; j++)
{
var formattedValue = dataGridView1.Rows[i].Cells[j].FormattedValue;
if (formattedValue != null && formattedValue.ToString().ToLower() == "неограничен")
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
}
}
}
прошу помощи с оптимизацией так как пока не силён в этом деле
GridView
(for (var i = 0; i < dataGridView1.Rows.Count; i++)
) зачем, достаточно одногоe.RowIndex
, т.е. достаточно обхода по колонкам