private void OnEditClass(object sender, EventArgs e) { FormEnterClass form = new FormEnterClass(CurrentClass.Name); if (form.ShowDialog() == DialogResult.OK) { int index = comboBoxClass.Items.IndexOf(CurrentClass.Name); comboBoxClass.Items.Remove(CurrentClass.Name); CurrentClass.Name = form.name; comboBoxClass.Items.Insert(index, CurrentClass.Name); comboBoxClass.SelectedIndex = index; groupBoxGrade.Text = CurrentClass.Name + " Grade"; } }
//This method is upon changing a class private void OnClassChange(object sender, EventArgs e) { //If the option selected is the first index, a new category is created. if (comboBoxClass.SelectedIndex == 0) { //Deselect text comboBoxClass.SelectedIndex = -1; //Open up category selection form FormEnterClass formEnterClass = new FormEnterClass(); if (formEnterClass.ShowDialog() == DialogResult.OK) { //Create the class SchoolClass schoolClass = new SchoolClass(formEnterClass.name); //Add it to the classList ClassList.Add(schoolClass); //Add it to the comboBoxClass comboBoxClass.Items.Add(schoolClass.Name); //Set the currentClassIndex to the last index CurrentClassIndex = ClassList.Count - 1; //Enable the comboBoxCategory if not enabled if (comboBoxCategory.Enabled == false) { comboBoxCategory.Enabled = true; } //Set the combobox text to the newly created class comboBoxClass.Text = CurrentClass.Name; //Update the groupboxgrade's text to the current class's name groupBoxGrade.Text = CurrentClass.Name + " Grade"; if (ClassList.Count != 1) { //Clear the rows dataGridView.Rows.Clear(); //Reset the text groupBoxTotals.Text = "Category Totals (%)"; labelLetterGrade.Text = ""; labelGrade.Text = ""; labelPtsPoss.Text = ""; labelScore.Text = ""; labelPercent.Text = ""; //Update the category list UpdateCategoryList(); //Disable the datagriview dataGridView.Enabled = false; saveToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true; } else { editClassToolStripMenuItem.Enabled = true; deleteClassToolStripMenuItem.Enabled = true; addCategoryToolStripMenu.Enabled = true; } } else if (ClassList.Count != 0) { comboBoxClass.Text = CurrentClass.Name; } } //Else, set the currentClassIndex to the index of the selected option minus one else { //Update the currentclassindex current index - 1 CurrentClassIndex = comboBoxClass.SelectedIndex - 1; //Update the groupboxgrade's text to the current class's name groupBoxGrade.Text = CurrentClass.Name + " Grade"; if (CurrentClass.CategoryList.Count != 0) { comboBoxCategory.Items.Clear(); comboBoxCategory.Items.Add("Create new category"); foreach (Category c in CurrentClass.CategoryList) { comboBoxCategory.Items.Add(c.Name); } //Update the combobox text to the current category's text comboBoxCategory.SelectedIndex = CurrentClass.CurrentCategoryIndex + 1; //Load the data LoadData(); //Store the data StoreData(); //Update the totals UpdateTotals(); //Update the grade UpdateGrade(); //Update the category list UpdateCategoryList(); dataGridView.Enabled = true; } else { comboBoxCategory.SelectedIndex = -1; comboBoxCategory.Items.Clear(); comboBoxCategory.Items.Add("Create new category"); labelLetterGrade.Text = ""; labelGrade.Text = ""; labelPtsPoss.Text = ""; labelScore.Text = ""; labelPercent.Text = ""; groupBoxTotals.Text = "Category Totals (%)"; dataGridView.Rows.Clear(); dataGridView.Enabled = false; } } }