protected override void DeleteBtn_Click(object sender, EventArgs e) { //Remove the event first - to prevent executing the other method dataGridView1.UserDeletingRow -= dataGridView1_UserDeletingRow; //Get Item Roti if (invoiceBindingSource.DataSource == null) { return; } if (dataGridView1.SelectedRows.Count == 0) { return; } //Confirm Delete if (DialogHelper.DeleteDialog(dataGridView1.SelectedRows.Count + " record(s)") != 0) { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { Invoice item = row.DataBoundItem as Invoice; if (item != null) { invoiceRepo.Delete(item); invoiceBindingSource.Remove(item); } } } //Assign the method again dataGridView1.UserDeletingRow += dataGridView1_UserDeletingRow; }
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { //Get Item if (invoiceBindingSource.DataSource == null) { e.Cancel = true; } if (dataGridView1.CurrentRow == null) { e.Cancel = true; } DataGridViewRow row = dataGridView1.CurrentRow; Invoice item = row.DataBoundItem as Invoice; //Confirm Delete if (DialogHelper.DeleteDialog(item.nomorInvoice) != 0) { if (item != null) { invoiceRepo.Delete(item); invoiceBindingSource.Remove(item); } } else { e.Cancel = true; } }
protected override void DeleteBtn_Click(object sender, EventArgs e) { //Get Item Roti if (outletBindingSource.DataSource == null) { return; } if (outletDataGridView.SelectedRows.Count == 0) { return; } //Confirm Delete if (DialogHelper.DeleteDialog(outletDataGridView.SelectedRows.Count + " record(s)") != 0) { foreach (DataGridViewRow row in outletDataGridView.SelectedRows) { Outlet item = row.DataBoundItem as Outlet; if (item != null) { outletRepository.Delete(item); outletBindingSource.Remove(item); } } } }
protected override void DeleteBtn_Click(object sender, EventArgs e) { //Verification if (productBindingSource.DataSource == null) { return; } if (productDataGridView.SelectedRows.Count == 0) { return; } //Confirm Delete if (DialogHelper.DeleteDialog(productDataGridView.SelectedRows.Count + " record(s)") != 0) { foreach (DataGridViewRow row in productDataGridView.SelectedRows) { Product item = row.DataBoundItem as Product; if (item != null) { productRepository.Delete(item); productBindingSource.Remove(item); } } } }
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { //Get Item if (pItemsBindingSource.DataSource == null) { e.Cancel = true; } if (dataGridView1.CurrentRow == null) { e.Cancel = true; } DataGridViewRow row = dataGridView1.CurrentRow; InvoiceDetail item = row.DataBoundItem as InvoiceDetail; //Confirm Delete if (DialogHelper.DeleteDialog(item.itemCode) != 0) { if (item != null) { if (isAddNew != true) { invoiceDetailRepository.Delete(item); } productBindingSource.Remove(item); } } else { e.Cancel = true; } }