//Adds students to the gridView based on the subject given. private void addStudents(Subject subject) { Student[] students = studentDatabase.getStudents(subject); for (int i = 0; i < students.Length; i++) { studentsGrid.addRecord(students[i]); } }
//Used to allow for right-clicking to remove subjects private void selectSubjectToRemove(object sender, MouseEventArgs e) { //http://stackoverflow.com/questions/5239913/get-rowindex-via-contextmenu if (e.Button == MouseButtons.Right) { DataGridView.HitTestInfo hit = ui.subjects.HitTest(e.X, e.Y); if (hit.Type == DataGridViewHitTestType.Cell) { subjectToRemove = (Subject)ui.subjects.Rows[hit.RowIndex].Cells[0].Value; ui.subjects.ContextMenuStrip.Items.Clear(); ui.subjects.ContextMenuStrip.Items.Add("Remove " + subjectToRemove.ToString()); } } }
//Removes all students for a particular subject from the gridView. private void removeStudents(Subject subject) { Student[] students = studentDatabase.getStudents(subject); foreach (Student s in students) { studentsGrid.removeRecord(s); } }