private void searcht_TextChanged(object sender, TextChangedEventArgs e) { string filterText = searcht.Text; ICollectionView cv = CollectionViewSource.GetDefaultView(teachertable.ItemsSource); if (!string.IsNullOrEmpty(filterText)) { cv.Filter = o => { tTeacher p = o as tTeacher; return(p.FirstName.ToUpper().StartsWith(filterText.ToUpper())); }; } else { teachertable.ItemsSource = db.tTeachers.ToList(); } }
private void Button_Click_4(object sender, RoutedEventArgs e) { try { tTeacher teacher = new tTeacher(); teacher.FirstName = firstnamet.Text; teacher.LastName = lastnamet.Text; teacher.Telephone = telephonet.Text; teacher.ContactEmail = emailt.Text; teacher.GroupFK = Convert.ToInt32(((ComboBoxItem)groupt.SelectedItem).HiddenValue); db.tTeachers.Add(teacher); db.SaveChanges(); teachertable.ItemsSource = db.tTeachers.ToList(); ClearBox(); } catch (Exception) { MessageBox.Show("Error while editing. Check: email, telephone number, group", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }