Операция недопустима, поскольку она приводит к повторному вызову функции SetCurrentCellAddressCore - PullRequest
0 голосов
/ 14 февраля 2019

Я пытаюсь проверить значение, введенное в ячейку.Если все в порядке, тогда сделайте что-нибудь еще, удалив всю строку, но возникнет исключение: «Операция недопустима, поскольку она приводит к повторному вызову функции SetCurrentCellAddressCore»

 Private Sub DgvItems_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DgvItems.CellEndEdit
    If e.ColumnIndex = 0 Then
        Dim cl As DataGridViewCell = DgvItems.Rows(e.RowIndex).Cells(0)
        Dim product As New Product(cl.Value)
        If String.IsNullOrWhiteSpace(product.SKU) Then
            MessageBox.Show("Product not found!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Dim row As DataGridViewRow = DgvItems.Rows(e.RowIndex)
            DgvItems.Rows.Remove(row) 'An exception is raised here

        Else
            Dim inv As New ProductInventory(product.SKU)
            Dim qt As Integer = inv.TargetLevel - (inv.StockLevel + inv.OldStock)
            DgvItems.Rows(e.RowIndex).Cells(1).Value = product.Barcode
            DgvItems.Rows(e.RowIndex).Cells(2).Value = product.Name
            DgvItems.Rows(e.RowIndex).Cells(3).Value = product.BuyPrice
            If qt < 0 Then
                DgvItems.Rows(e.RowIndex).Cells(4).Value = "1"
            Else
                DgvItems.Rows(e.RowIndex).Cells(4).Value = qt
            End If
        End If
    End If
End Sub
...