There is a C # code. It completely fulfills its requirements, but the problem is that the dataGridView is very slow.
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; } } } I ask for help with optimization since I am not strong in this matter.
GridViewtwice (for (var i = 0; i < dataGridView1.Rows.Count; i++)) why, one thing is enough - Balde.RowIndex, i.e. enough column walk - Bald