private void bindingItem_ListChanged(object sender, ListChangedEventArgs e) { /* This event will be called several times during form initialization. * We don't want to do anything with it until the runtime author * list has been passed in. */ // Exit if no parent InvoiceItem parent = (InvoiceItem)bindingInvoice.Current; if (parent == null) { return; } // Get the item affected int index = e.NewIndex; rotiItem changedItem = null; if ((index > -1) && (index < parent.Items.Count)) { changedItem = parent.Items[index]; } // Get the type of change that occured ListChangedType changeType = e.ListChangedType; /* We only need to respond to two types of changes here; updates * and moves. Adds are handled by bindingSourceAuthors_AddingNew(), * and deletes are handled by menuItemBooksDelete_Click(). */ // Dispatch a change handler switch (changeType) { case ListChangedType.ItemChanged: if (changedItem.ItemCode != null) { CommandUpdateItem updateItem = new CommandUpdateItem(changedItem); m_AppController.ExecuteCommand(updateItem); } else { CommandDeleteItem deleteItem = new CommandDeleteItem(changedItem); m_AppController.ExecuteCommand(deleteItem); } break; case ListChangedType.ItemMoved: // Not supported in this app break; } m_Invoices.ResetBindings(); }
private void deleteBtn_Click(object sender, EventArgs e) { if (m_ItemList == null) { return; } itemMaster m_item = (itemMaster)itemMasterBindingSource.Current; CommandDeleteItem deleteitem = new CommandDeleteItem(m_ItemList, m_item); itemMaster itemDelete = (itemMaster)m_AppController.ExecuteCommand(deleteitem); }
private void deleteBookToolStripMenuItem_Click(object sender, EventArgs e) { //Get Item Roti InvoiceItem parent = (InvoiceItem)bindingInvoice.Current; //Confirm Delete string message = String.Format("Delete Items ? "); DialogResult result = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); //Delete Item if (result == DialogResult.Yes) { foreach (DataGridViewRow row in dgItem.SelectedRows) { rotiItem item = row.DataBoundItem as rotiItem; if (item != null) { CommandDeleteItem deleteItem = new CommandDeleteItem(parent, item); m_AppController.ExecuteCommand(deleteItem); } } } }