Datagridview specific rows change background color

299 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 answers

0
Jack.D On BEST ANSWER

Just use the dataGridView_CurrentCellChanged event can solve this problem.