private void resetList() { //set source of the items as users in list lstViewStuds.ItemsSource = students; students.Clear(); if (!ifSearch) { //Couldn't get inner join in linq working so using this method to populate the list foreach (var stud in db.Users.Where(s => s.user_role == "student")) { //if users result class id equals the class id of the teacher(need teachers id to find the right class first) //create a new instance of a student to add to list listStudents newStudent = new listStudents { User_id = stud.user_id, Student_name = stud.username, Address = stud.address, Dob = stud.dob }; //this foreach gets the mark from the result table foreach (var result in db.Results.Where(r => r.user_id == newStudent.User_id)) { newStudent.Mark = result.result_mark; //suppose to add class id to a list in the instance //newStudent.Class_id.Add(result.class_id); } students.Add(newStudent); } } else if (ifSearch) { //Couldn't get inner join in linq working so using this method to populate the list foreach (var stud in db.Users.Where(s => s.user_role == "student" && s.name.Contains(searchString))) { //if users result class id equals the class id of the teacher(need teachers id to find the right class first) //create a new instance of a student to add to list listStudents newStudent = new listStudents { User_id = stud.user_id, Student_name = stud.username, Address = stud.address, Dob = stud.dob }; //this foreach gets the mark from the result table foreach (var result in db.Results.Where(r => r.user_id == newStudent.User_id)) { newStudent.Mark = result.result_mark; //suppose to add class id to a list in the instance //newStudent.Class_id.Add(result.class_id); } students.Add(newStudent); } } lstViewStuds.Items.Refresh(); }
private void LstViewStuds_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (lstViewStuds.SelectedIndex >= 0) { //set the local user variable to the selected item in the list view selectedUser = students.ElementAt(lstViewStuds.SelectedIndex); if (selectedUser.User_id >= 0) { viewStudentsResults.IsEnabled = true; } } }