private void FilterDataGrid() { IEnumerable <BloodDonation> temporaryFilteredDonations = Donations.AsEnumerable(); var bloodType = BloodTypeComboBox.SelectedItem; var donorPesel = DonorPeselTextBox.Text; var bloodTakerPesel = BloodTakerTextBox.Text; if (bloodType != null) { temporaryFilteredDonations = temporaryFilteredDonations.Where(x => x.BloodType.ToString() == bloodType.ToString()); } if (donorPesel != "") { temporaryFilteredDonations = temporaryFilteredDonations.Where(x => x.Donor.Pesel.Contains(donorPesel)); } if (bloodTakerPesel != "") { temporaryFilteredDonations = temporaryFilteredDonations.Where(x => x.BloodTaker.Pesel.Contains(bloodTakerPesel)); } FilteredDonations.Clear(); foreach (var temporaryFilteredDonation in temporaryFilteredDonations) { FilteredDonations.Add(temporaryFilteredDonation); } }