Vikas Ahlawat

Vikas Ahlawat

  • NA
  • 564
  • 808.8k

Datagridview Row backcolor problem

Apr 20 2012 2:49 AM
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)