private void BtnDelete_Click(object sender, RoutedEventArgs e) { try { if (cboAttribute.SelectedIndex > -1) { if (ScreenMode.Location == screenmode) { if (cboAttribute.SelectedItem != null) { //Call the API if the selected item isn't null to delete it HttpClient client = InitializeClient(); HttpResponseMessage response = new HttpResponseMessage(); Location location = locations.ElementAt(cboAttribute.SelectedIndex); response = client.DeleteAsync("Location/" + location.Id).Result; locations.Remove(location); Rebind(); txtDescription.Focus(); txtDescription.SelectAll(); } } else if (ScreenMode.Gender == screenmode) { if (cboAttribute.SelectedItem != null) { //Call the API if the selected item isn't null to delete it HttpClient client = InitializeClient(); HttpResponseMessage response = new HttpResponseMessage(); Gender gender = genders.ElementAt(cboAttribute.SelectedIndex); response = client.DeleteAsync("Gender/" + gender.Id).Result; genders.Remove(gender); Rebind(); txtDescription.Focus(); txtDescription.SelectAll(); } } else if (ScreenMode.Race == screenmode) { if (cboAttribute.SelectedItem != null) { //Call the API if the selected item isn't null to delete it HttpClient client = InitializeClient(); HttpResponseMessage response = new HttpResponseMessage(); Race race = races.ElementAt(cboAttribute.SelectedIndex); response = client.DeleteAsync("Race/" + race.Id).Result; races.Remove(race); Rebind(); txtDescription.Focus(); txtDescription.SelectAll(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!"); } }