private void Delete_Song(object sender, RoutedEventArgs e) { if (playListBox.SelectedItem.ToString() == "All Music") { DataRowView currentItem = songGrid.SelectedItem as DataRowView; int songID = (int)currentItem["id"]; //https://social.msdn.microsoft.com/Forums/vstudio/en-US/d3f223ac-7fca-486e-8939-adb46e9bf6c9/how-can-i-get-yesno-from-a-messagebox-in-wpf?forum=wpf if (MessageBox.Show("Are you sure you wish to delete this song?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { } else if (currentItem != null) { musicLibrary.DeleteSong(songID); } } else { DataRowView currentItem = songGrid.SelectedItem as DataRowView; var current = currentItem.Row.ItemArray; //Same method of retrieving the songID above wouldn't work for playlist songs... int songID = Convert.ToInt32(current[0]); int position = Convert.ToInt32(currentItem["position"]); musicLibrary.RemoveSongFromPlaylist(position, songID, playListBox.SelectedItem.ToString()); var selectedPlaylist = playListBox.SelectedItem.ToString(); var songs = musicLibrary.SongsForPlaylist(selectedPlaylist); songGrid.ItemsSource = songs.DefaultView; } }
private void Removebtn_click(object sender, RoutedEventArgs e) { var playlist = playlistListBox.SelectedItem?.ToString(); Song s = dataGrid.SelectedItem as Song; if (playlist == "All Music" || playlist == null) { string msgtext = "Are you sure you want to remove this song?"; string txt = "Confirmation"; MessageBoxImage icon = MessageBoxImage.Question; MessageBoxButton button = MessageBoxButton.YesNo; if (MessageBox.Show(msgtext, txt, button, icon) == MessageBoxResult.Yes) { musicLib.DeleteSong(s.Id); } } else { //remove from playlist musicLib.RemoveSongFromPlaylist(s.Position, s.Id, playlist); } RefreshSongs(); }
private void RemoveSong_Click(object sender, RoutedEventArgs e) { //Code found at : //http://stackoverflow.com/questions/10777123/c-sharp-messagebox-dialog-result if (MessageBox.Show("Are you sure you want to delete this song from the list?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { DataRowView row = (DataRowView)dataGrid.SelectedItem; int id = Int16.Parse(row["id"].ToString()); musicLib.DeleteSong(id); musicLib.Save(); } }
private void Delete_MenuItemClick(object sender, RoutedEventArgs e) { // Get the song id int songId = findSelectedRowInDataGrid(); // Remove the song from all playlist if (songId != -1 || songId != null && playlistName == "All Music") { Song s = musicLib.GetSong(songId); string name = s.Title; musicLib.DeleteSong(songId); MessageBox.Show(name + " has been removed from the library."); } }