In order to initialize my VouchersDGV Data Grid View I’m Using the following
DGV.AllowUserToDeleteRows = True
For i = 1 To DGV.RowCount - 1
DGV.Rows.Remove(DGV.Rows(i - 1))
DGV.Refresh()
Next
But when I’m runing it for the first time I take the error of
{“Uncommitted new row cannot be deleted.”} System.InvalidOperationException
If I will continue and run my code and write a new row in my Data Grid and I will try to initialize again (now I have two rows, one has the data and the other is empty) I take this error
{“Uncommitted new row cannot be deleted.”} System.InvalidOperationException
I can’t solve it, Please is there someone to assist me on that?
Add this condition to your loop. Alternatively, you could also use DGV.RejectChanges() which will reset all the row status to original.