private void gv_Books_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex > -1 && e.RowIndex > -1) { var cell = gv_Books.CurrentCell; var quantity = Convert.ToInt64(gv_Books.Rows[e.RowIndex].Cells[gv_Books_clm_CartQuantity.Name].Value.ToString()); var cartQuantity = cell.Value?.ToString(); var result = _bookValidator.ValidateQuantity(quantity, cartQuantity); if (!result.State) { cell.ErrorText = result.Result; cell.Value = "0"; } else { cell.ErrorText = ""; } } }