There is a DataGridView in it come values from the database, where for a certain period the cell is highlighted in red.
But over time, the base has grown greatly, and a color filter was required. On one of the forums I found
private void checkBox1_CheckedChanged(object sender, EventArgs e) { foreach (DataGridViewRow r in dataGridview1.Rows) { if(r.DefaultCellStyle.BackColor == Color.Red) { } } } But it loads the process a lot and it doesn’t work, and I don’t know where to put the result.
UPD
if(datagridview.rows[e.rowindex].Cells["Срок_до"].value !=null &&((DateTime)datagridview.rows[e.rowindex].Cells["Срок_до"].value).CompareTo(datetime <0) { datagridview.rows[e.Rowindex].defaultcellstyle = color.red } for (var index = 0; index<datagridview.Columns.Count; ++index) { var formattedvalue = datagridview.Rows[e.RowIndex].Cell[index].FormattedValue; if(formattedvalue==null) continue; var str = formattedvalue.ToString().ToLower(); if(str!="удален") { if(str=="неограничен") datagridview.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow; } else datagridview.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Gray; } } Data from the database
Adapter = new MySqlDataAdapter("SELECT * FROM dist", new MySqlConnection(Connect.ToString())); Adapter.Fill(dt); datagrid.DataSource = dt; UPD is now filtered like this:
var dataview = new DataView(dt) { RowFilter = $"Срок_до < '{datetime}' AND Комментарии = '' AND Статус_отработки = ''" } But there is a snag because there are 3 colors and you need to make it so that only 1 color is red.
UPD
Please help

Но со временем база сильно разрослась, и потребовалась сортировка по цвету...What is the relationship between the size of the database and sorting by color? - sp7