Add one more condition which is gridMappings.Rows.Count>0
private void gridMappings_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
if (this.gridMappings.DataSource != null)
{
int lastRow =0;
if(gridMappings.Rows.Count>0)
lastRow this.gridMappings.Rows.Count - 1;
for (int i = 0; i < this.gridMappings.Rows.Count; i++)
{
if (this.gridMappings.Rows[i] != null)
{
this.gridMappings.Rows[i].Cells[2].Value = "Add";
}
else
{
this.gridMappings.Rows[i].Cells[2].Value = "Edit";
}
}
}
}