public CameraSettingsContainer DeleteCurrent() { if (CameraSettingsList.Count < 1) { MessageBox.Show("Cannot Delete the last Camera Settings Item", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBoxResult result = MessageBox.Show("Are you sure you want to delete: " + CurrentCameraSettings.Description + "?", "Delete Camera Setting Item", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { // save item to delete bool needToResetDefault = false; CameraSettingsContainer itemToDelete = CurrentCameraSettings; if (itemToDelete.IsDefault) { needToResetDefault = true; } // find item to be the new current item foreach (var cs in CameraSettingsList) { if (cs.CameraSettingID != itemToDelete.CameraSettingID) { bool success = _wgDB.DeleteCameraSettings(itemToDelete.CameraSettingID); if (success) { CurrentCameraSettings = cs; if (needToResetDefault) { CurrentCameraSettings.IsDefault = true; } CameraSettingsList.Remove(itemToDelete); } break; } } } } return(CurrentCameraSettings); }