public void InsertFile(int index, string fileName) { PlaylistItem item = new PlaylistItem(fileName, false); Playlist.Insert(index, item); PopulatePlaylist(); }
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]; } }