private void btnDelete_Click(object sender, EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) { // Tain Rose & Asia Passmore, 2/26/2021 // 18-1 Extra Teamwork, step 13 & 14 string displayText = lstItems.Items[i].ToString(); InvItem invItem = invItems .Where(item => item.DisplayText == displayText) .FirstOrDefault(); string message = $"Are you sure you want to delete {invItem.Description}?"; DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { invItems.Remove(invItem); InvItemDB.SaveItems(invItems); FillItemListBox(); } } }
private void btnDelete_Click(object sender, EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) { // Add code here that displays a dialog box to confirm // the deletion and then removes the item from the list, // saves the list of products, and refreshes the list box // if the deletion is confirmed. int t = lstItems.SelectedIndex; if (t != -1) { InvItem invItem = invItems[t]; string message = "Are you sure you want to delete " + invItem.Description + "?"; DialogResult button = MessageBox.Show(message, "Confirm Deletion", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { invItems.Remove(invItem); InvItemDB.SaveItems(invItems); FillItemListBox(); } } } }
private void btnAdd_Click(object sender, System.EventArgs e) { frmNewItem newItemForm = new frmNewItem(); InvItem invItem = newItemForm.GetNewItem(); if (invItem != null) { invItems.Add(invItem); InvItemDB.SaveItems(invItems); FillItemListBox(); } }
private void btnAdd_Click(object sender, EventArgs e) { // Add code here that creates an instance of the New Item form // and then gets a new item from that form. frmNewItem newItemForm = new frmNewItem(); InvItem invItem = newItemForm.GetNewItem(); if (invItem != null) { invItems.Add(invItem); InvItemDB.SaveItems(invItems); FillItemListBox(); } }
private void btnDelete_Click(object sender, System.EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) { InvItem invItem = (InvItem)invItems[i]; string message = "Are you sure you want to delete " + invItem.Description + "?"; DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo); if (button == DialogResult.Yes) { invItems.Remove(invItem); InvItemDB.SaveItems(invItems); FillItemListBox(); } } }
private void btnDelete_Click(object sender, EventArgs e) { int i = lstItems.SelectedIndex; if (i != -1) // check if an inventory item has been selected { // Add code here that displays a dialog box to confirm // the deletion and then removes the item from the list, // saves the list of products, and refreshes the list box // if the deletion is confirmed. InvItem invItem = invItems[i]; // create & set variable for selected inventory item string message = "Are you sure you want to delete: " + invItem.ItemNo + " " + invItem.Description + "?"; // create delete confirmation message DialogResult button = MessageBox.Show(message, "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2); // display confirmation to delete if (button == DialogResult.Yes) // check if user confirmed deletion { invItems.Remove(invItem); // remove selected item from list InvItemDB.SaveItems(invItems); // save updated items list FillItemListBox(); // call method to refresh items list box } } }
public void Save() { InvItemDB.SaveItems(invItems); }