5
Answers

Datagridview Row backcolor problem

Vikas Ahlawat

Vikas Ahlawat

12y
5.1k
1
Hi I am facing problem in changing datagridview rows color based on data. but in my datagrid last row containing total so I don't want to apply any background color on it.
I sent the cor or cellRormatting event of datagridview
Here I am using (e.RowIndex!= dgvRoomTypeSeven.Rows.Count-1) to check that it is last row.
but e.RowIndex always gives 0 why?


private void dgvRoomTypeSeven_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  {
 
  if (e.ColumnIndex != 0 && e.RowIndex!= dgvRoomTypeSeven.Rows.Count-1)
  {
  if (e.Value.ToString() == "N/A") e.CellStyle.BackColor = Color.Red;
  else
  e.CellStyle.BackColor = Color.Green;
  }
  }

Is there any other way?


Answers (5)