private void buttonAddItem_Click(object sender, EventArgs e) { var addedItem = ItemForm.ShowAddItemDialog(this, categories, listViewCategories.SelectedIndex); if (addedItem == null) { return; } ShowItemList(categories.IndexOf(addedItem.Category)); listViewCategories.SelectObject(addedItem.Category); needUpdate = true; }
private void menuItemAdd_Click(object sender, EventArgs e) { Item item = ItemForm.ShowAddItemDialog(this, categories, 0); if (item != null) { if (item.Image != null && item.ImageId != null && !ImageList.Images.ContainsKey(item.ImageId)) { ImageList.Images.Add(item.ImageId, item.Image); } SetupUIAsync(); } }
public static Item ShowAddItemDialog(Form parent, List <Category> categories, int selectedCategoryIndex) { if (categories == null || categories.Count <= 0) { MessageBox.Show("Vous devez d'abord créer une catégorie", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } ItemForm addItemForm = new ItemForm(categories, selectedCategoryIndex); addItemForm.categories = categories; addItemForm.ShowDialog(parent); return(addItemForm.DialogResult == DialogResult.OK ? addItemForm.item : null); }
private void contextMenuItemEdit_Click(object sender, EventArgs e) { var item = listViewItems.SelectedObject as Item; int oldCategoryIndex = categories.IndexOf(item.Category); ItemForm editItemForm = new ItemForm(categories, oldCategoryIndex, item); editItemForm.ShowDialog(this); if (editItemForm.DialogResult != DialogResult.OK) { return; } listViewCategories.SelectObject(item.Category); ShowItemList(categories.IndexOf(item.Category)); XmlManager.SaveCategories(categories); needUpdate = true; }