public Form1() { InitializeComponent(); foreach (Book.Category cat in Enum.GetValues(typeof(Book.Category))) { comboBox1.Items.Add(cat); } Book.Category currentCategory = (Book.Category)Enum.Parse(typeof(Book.Category), comboBox1.SelectedValue.ToString()); //populate the listbox with the current List<books> button1.Click += (sender, e) => { Book newBook = new Book(textBox1.Text, textBox2.Text, int.Parse(textBox3.Text), double.Parse(textBox4.Text), new Pen(Color.Blue), currentCategory); bookList.Add(newBook); booksChanged(sender, e); }; booksChanged += new bookCollectionChanged(UpdateBooks); bookList.CollectionChanged += UpdateBooks; //Listener for all Textboxes var TextboxListener = new EventHandler(Txt_TextChanged); foreach (var ctrl in Controls) { if (ctrl is TextBox txtBox) { txtBox.TextChanged += TextboxListener; } } button2.Click += new EventHandler(XMLCreator); button1.Click += new EventHandler(ClearTextboxes); listBox1.DisplayMember = "title"; }
public void AddNewBook(int quantity, string name, DateTime printdate, Book.Category category) { Book book = new Book(quantity, name, printdate, category); _items.Add(book); }