private void buttonUpdate_Click(object sender, EventArgs e) { //get listbox's selected item's index int selectedIndex = listBoxScores.SelectedIndex; //if there is an invalid index selected, return if (selectedIndex == -1) { return; } //get the score to update int selectedScore = (int)listBoxScores.SelectedItem; //create a form with action "Update" and the current score to be updated prefilled FormScore score = new FormScore("Update", selectedScore.ToString()); //show dialog DialogResult result = score.ShowDialog(); switch (result) { case DialogResult.OK: //remove the old score scoreList.RemoveAt(selectedIndex); //put new score where the old one was in scorelist scoreList.Insert(selectedIndex, (int)score.Tag); break; } }
//event when the add button is clicked private void buttonAdd_Click(object sender, EventArgs e) { //create a form with action "Add" FormScore score = new FormScore("Add"); //display the form DialogResult result = score.ShowDialog(); switch (result) { case DialogResult.OK: //add the score from the dialog form to the scorelist scoreList.Add((int)score.Tag); break; } }