The problem is this: there is a table in which the rows are highlighted in color (whose value is one column larger than the textBox) ... if I allow entering the value 5, say 3 lines will be colored, and if you enter 6 here, then rows should be less ... how to put color cleaning?

The code is:

for (int i = 0; i < DataGridView.Rows.Count; i++) { int st = int.Parse(textBox2.Text); if (int.Parse(DataGridView.Rows[i].Cells[2].Value.ToString()) > st) { for (int j = 0; j < 3; j++) { DataGridView.Rows[i].Cells[j].Style.BackColor = Color.LightGreen; DataGridView.Rows[i].Cells[j].Style.SelectionBackColor = Color.LightGreen; } } } 

    1 answer 1

    track the TextChange event at textBox2:

     textBox2.TextChange+= (s,e)=>{ //вернуть дефолтный цвет у всей таблицы: ... //пересчитать и окрасить снова: for (int i = 0; i < DataGridView.Rows.Count; i++) { int st = int.Parse(textBox2.Text); if (int.Parse(DataGridView.Rows[i].Cells[2].Value.ToString()) > st) { for (int j = 0; j < 3; j++) { DataGridView.Rows[i].Cells[j].Style.BackColor = Color.LightGreen; DataGridView.Rows[i].Cells[j].Style.SelectionBackColor = Color.LightGreen; } } } }