try it
for (int i = dgvData.Rows.Count - 1; i >= 0; i--) { dgvData.Rows.Remove(dgvData.Rows[i]); }
you use a ForEach loop and delete the rows of the same collection, i.e. dgvData.Rows. This is his missing object from this collection and failed to skip every item.
So in order to deal with this, you need to get hung up on using the above code.
You need to set the value i accordingly for the new line, if it allows you to add a new line ....
source share