Datagridview specific rows change background color

305 Views Asked by At

i try to highlight the selected row become red where column is 'E' in datagridview but if the first row's status is 'E',the following row also become red too although status is 'I'.

enter image description here

SelectionChanged event

int sel = datagridview.SelectedCells[0].RowIndex;
    DataGridViewRow Row = dataGridView.Rows[sel];
    if(!File.Exists(path))
    {
       Row.Cells[4].Value = "E"
       for(int i=0;i<5;i++)
       {
          Row.Cells[i].Style.BackColor = Color.Red;
       }
    }

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Just use the dataGridView_CurrentCellChanged event can solve this problem.