This is in my RowValidation DataGridView function:
DataGridViewRow row = viewApplications.Rows[e.RowIndex]; if (row.Cells[colApplyTo.Index].Value == (object)-1) { if (MessageBox.Show("Row #" + (e.RowIndex + 1) + " is not assigned to a charge. Would you like to correct this? (If no, the row will be deleted)", "Invalid Row", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { viewApplications.Rows.RemoveAt(e.RowIndex); } else { e.Cancel = true; } }
However, there is a problem if the user says no, which means that he or she does not correct this line, I cannot delete it, as I try to do. I get an exception: InvalidOperationException: The operation cannot be performed in this event handler
How can I fix this and delete the line?
source share