private void addButton_Click(object sender, EventArgs e) { // Create a basic one Envir.CreateRecipieShopContent(); // Select the last item (I.E The new object added) This will update the form as well. _selectedContent = Envir.RecipeShopContents[Envir.RecipeShopContents.Count - 1]; UpdateInterface(true); listBox1.SelectedItem = _selectedContent; }
public void UpdateInterface(bool refresh = false) { // Clear the List Box of objects if (refresh) { listBox1.Items.Clear(); // Cycle through the Object List for (int i = 0; i < Envir.RecipeShopContents.Count; i++) { // Add each object to the List Box listBox1.Items.Add(Envir.RecipeShopContents[i]); } } if (listBox1.SelectedItem != null) { _selectedContent = (RecipeShop)listBox1.SelectedItem; } // Set Boxes to defaults itemBox.Text = ""; priceBox.Text = ""; // If an object is Selected if (_selectedContent != null) { // Set the text boxes with the Objects Values if (_selectedContent.ItemBeingSold != null) { itemBox.Text = _selectedContent.ItemBeingSold.Name; } if (_selectedContent.ItemPrice > 0) { priceBox.Text = _selectedContent.ItemPrice.ToString(); } if (listBox1.SelectedItem != _selectedItem) { listBox1.SelectedItem = _selectedContent; } } }