//Constructor public MainWindow() { InitializeComponent(); dis1 = new DisplayStudents(); selectedStudent = null; context = new Model1(); passedStudents = new StudentList(); failedStudents = new StudentList(); }
private void editSelectionChanged(object sender, SelectionChangedEventArgs e) { if (buttonDisabled) { mw.editStudent.IsEnabled = true; buttonDisabled = false; } studentList = (StudentList)studentGrid.DataContext; //When deleting a student the list box can become confused due to //the selected index disappearing. If it gets confused this resets //the selected item back to the default -1 try { mw.SelectedStudent = studentList[studentListBox.SelectedIndex]; } catch { studentListBox.SelectedIndex = -1; mw.editStudent.IsEnabled = false; buttonDisabled = true; } e.Handled = true; }
//Window Loaded public void Window_Loaded(object sender, RoutedEventArgs e) { //Find the resource oc = FindResource("myStudentList") as StudentList; //Query for all students all = from student in context.Students select student; totalCounter = 0; passedCounter = 0; //Add students to resource and count how many students foreach (var result in all) { oc.Add(result); totalCounter++; } //Count students that have achieved either an A, B, C or D passing grade foreach (var student in oc) { if (student.gradePassed(student.FinalGrade)) { studentPassed(student); } else { studentFailed(student); }; } PercentPassedCalc(totalCounter, passedCounter); //Displays the listbox, labels, etc. in the frame Main.Content = dis1; }