private void RemoveSelectedItems() { var rowIndexes = new List <int>(); try { if (Playlist.Count <= 0) { return; } if (dgv_PlayList.CurrentRow != null) { selectedRowIndex = dgv_PlayList.CurrentRow.Index; } rowIndexes.AddRange(from DataGridViewRow r in dgv_PlayList.SelectedRows select r.Index); foreach (int index in rowIndexes.OrderByDescending(v => v)) { if (index == currentPlayIndex) { CloseMedia(); } Playlist.RemoveAt(index); } PopulatePlaylist(); if (selectedRowIndex < 0) { selectedRowIndex = 0; } else if (selectedRowIndex > Playlist.Count - 1) { selectedRowIndex = Playlist.Count - 1; } dgv_PlayList.CurrentCell = Playlist.Count > 0 ? dgv_PlayList.Rows[selectedRowIndex].Cells[titleCellIndex] : dgv_PlayList.CurrentCell = null; } catch (Exception ex) { PlayerControl.HandleException(ex); } }
void dgv_PlayList_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length == 1) { var filename = files[0]; if (Directory.Exists(filename)) { var media = playListUi.GetMediaFiles(filename); AddFiles(media.ToArray()); return; } else if (PlayerExtensions.Playlist.Playlist.IsPlaylistFile(filename)) { OpenPlaylist(filename); return; } } var actualFiles = files.Where(file => !Directory.Exists(file)).Where(file => openFileDialog.Filter.Contains(Path.GetExtension(file))); AddFiles(actualFiles.ToArray()); dgv_PlayList.CurrentCell = dgv_PlayList.Rows[dgv_PlayList.Rows.Count - 1].Cells[titleCellIndex]; SetPlayStyling(); } else if (e.Data.GetDataPresent(typeof(DataGridViewRow))) { var clientPoint = dgv_PlayList.PointToClient(new Point(e.X, e.Y)); int destinationRow = dgv_PlayList.HitTest(clientPoint.X, clientPoint.Y).RowIndex; if (destinationRow == -1 || destinationRow >= Playlist.Count) { return; } var playItem = Playlist.ElementAt(dragRowIndex); Playlist.RemoveAt(dragRowIndex); NotifyPlaylistChanged(); Playlist.Insert(destinationRow, playItem); PopulatePlaylist(); dgv_PlayList.CurrentCell = dgv_PlayList.Rows[destinationRow].Cells[titleCellIndex]; } }
public void RemoveFile(int index) { Playlist.RemoveAt(index); PopulatePlaylist(); }