I’m trying to delete a row from a DataGridView
I use two types of instuctions
A
VouchersDGV.Rows.Clear()
B
If Not DGV.Rows(RowIndex).IsNewRow Then
DGV.Rows.RemoveAt(RowIndex)
DGV.Refresh()
End If
Both of them from inside of
VouchersDGV_RowValidating
Event
I also run it from another Event Handler with RaiseEvent.
The last Event handler I’m useing it to escape from inside of the row in case of wrong typing or… what ever and bring the datagrid to it’s initial position
The Event is
Private Sub Supplier_prod_EscapeOnFirstRowPressed() Handles Me.EscapeOnFirstRowPressed
To delete the row I’m enter to above EventHandler from
VouchersDGV_RowValidating
EventHandler and I take back the same error
DGV.Rows.RemoveAt(0) {"Operation cannot be performed in this event handler."}
Personally I can’t understand why that happen and how i can give a solution
Is there anybody to know about this error?
At the point of validation, it is relying on a particular state, and it obviously isn’t happy for you to start changing the rows when it only asked you to validate something. I can’t say I blame it; having to re-validate the scenario after every event would get… confusing; better to prevent the change.
You could instead queue the item for removal, on a timer of another callback, or maybe there is a mechanism for saying “no” during validation.