//Button add new Category. private void buttonAddCategory_Click(object sender, EventArgs e) { //Make new Category object Category addCategory = new Category(); //Make new CatecoryAddOrEditForm object and pass a new Category object to the form. CategoryAddOrEditForm CategoryAddOrEditForm = new CategoryAddOrEditForm(addCategory); CategoryAddOrEditForm.FormClosed += Form1_Load; CategoryAddOrEditForm.Show(); }
//Button edit Category. private void buttonEditCategory_Click(object sender, EventArgs e) { if (comboBoxMainEditCategory.SelectedItem != null) { //Find selected Category and add it to the Category Object. Category addCategory = Program.db.Categories.Find(comboBoxMainEditCategory.SelectedValue); //Make new CategoryAddOrEditForm object and pass the selected Category object to the form. CategoryAddOrEditForm CategoryAddOrEditForm = new CategoryAddOrEditForm(addCategory); CategoryAddOrEditForm.FormClosed += Form1_Load; CategoryAddOrEditForm.Show(); } //Clears datasource. comboBoxMainEditCategory.DataSource = null; //Rerun method Dictionary to refresh comboboxes and listview. Dictionary(); }