|
自己解決しました。
ソースコードを以下に示します。
/// <summary>
/// 選択されたダウンロードのドラッグを開始します。
/// </summary>
private void CDownloadListView_ItemDrag(object sender, ItemDragEventArgs e)
{
if (CDownloadListView.SelectedItems.Count > 0)
{
List<string> filelist = new List<string>();
foreach (ListViewItem item in CDownloadListView.SelectedItems)
{
try
{
string file = ((e.Item as ListViewItem).Tag as Downloader).Location;
if (File.Exists(file))
filelist.Add(file);
}
catch { }
}
if (filelist.Count > 0)
{
DataObject fdata = new DataObject(DataFormats.FileDrop, filelist.ToArray());
DoDragDrop(fdata, DragDropEffects.Copy);
}
DataObject idata = new DataObject(CDownloadListView.SelectedIndices);
DoDragDrop(idata, DragDropEffects.Move);
}
}
private void CDownloadListView_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListView.SelectedIndexCollection)))
e.Effect = DragDropEffects.Move;
}
/// <summary>
/// ドロップされたダウンロードを並べ替えます。
/// </summary>
private void CDownloadListView_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListView.SelectedIndexCollection)))
{
Point p = CDownloadListView.PointToClient(Cursor.Position);
ListViewItem baseitem =
CDownloadListView.GetItemAt(p.X, p.Y);
if (baseitem != null)
{
ListView.SelectedIndexCollection indices =
(ListView.SelectedIndexCollection)e.Data.GetData(typeof(ListView.SelectedIndexCollection));
List<ListViewItem> items = new List<ListViewItem>();
CDownloadListView.SuspendLayout();
foreach (int index in indices)
{
ListViewItem item = CDownloadListView.Items[index];
if (item == baseitem)
return;
items.Add(item);
}
foreach(ListViewItem item in items)
CDownloadListView.Items.Remove(item);
items.Reverse();
int baseindex = baseitem.Index;
foreach (ListViewItem item in items)
CDownloadListView.Items.Insert(baseindex, item);
CDownloadListView.ResumeLayout();
}
}
}
|