I have items in a datagridview using windows application C#, and I created the event `DataGrid_RowPostPaint` to generate serial number for each row in the datagridview.

Now when I save the data it is saving but not exits from the window and hang, I used break point to follow up why its hang after save, then I found that its looping in this event and not exit when reach to the last row in datagridview. 

This is the code: 

```
private void TestsDataGrid_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
    this.TestsDataGrid.Rows[e.RowIndex].Cells["Serial"].Value = (e.RowIndex + 1).ToString();
}

```

How to update the code in the event to exit from the event and end the loop when reach to the last row in datagridview.