private void searchs_TextChanged(object sender, TextChangedEventArgs e) { string filterText = searchs.Text; ICollectionView cv = CollectionViewSource.GetDefaultView(studenttable.ItemsSource); if (!string.IsNullOrEmpty(filterText)) { cv.Filter = o => { tStudent p = o as tStudent; return(p.FirstName.ToUpper().StartsWith(filterText.ToUpper())); }; } else { studenttable.ItemsSource = db.tStudents.ToList(); } }
private void Button_Click_6(object sender, RoutedEventArgs e) { try { tStudent student = new tStudent(); student.FirstName = firstnames.Text; student.LastName = lastnames.Text; student.IDCode = Convert.ToInt64(idcode.Text); student.School = school.Text; student.Class = Convert.ToInt32(_class.SelectedItem); student.Telephone = telephones.Text; student.ContactEmail = emails.Text; student.GroupFK = Convert.ToInt32(((ComboBoxItem)groups.SelectedItem).HiddenValue); db.tStudents.Add(student); db.SaveChanges(); studenttable.ItemsSource = db.tStudents.ToList(); ClearBox(); } catch (Exception ex) { MessageBox.Show("Error while editing. Check: email, telephone number, group" + ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }