On form load event when I load data in datagridview after that I call this function to change color of those rows in which the paid expense is Yes but it gives me nullreference exception on the line
PaidStatus = ExpensesDataGridView.Rows[i].Cells[4].Value.ToString();
public void ExpenseRowColor()
{
int i;
string PaidStatus;
for (i = 1; i <= ExpensesDataGridView.Rows.Count; i++)
{
PaidStatus = ExpensesDataGridView.Rows[i].Cells[4].Value.ToString();
if (PaidStatus == "Yes")
{
ExpensesDataGridView.Rows[i].DefaultCellStyle.BackColor = Color.LightGreen;
}
}
}