私は2つのリストビュー[listView1、listLocal]を持っています。それらはローカルPCとリモートPCの2つのファイルエクスプローラーで、
アイテムをドラッグした同じリストビューにドロップしている場合、コピー/移動する必要があります。そうでなければ、アイテムを他のリストビューにドロップしている場合は、送受信する必要があります。
したがって、listLocal はローカル PC 用のファイル エクスプローラーであり、listView1 はリモート PC 用です。
だから私が必要なのは、ドラッグしたアイテムを他のリストビューにドロップしているかどうかをチェックする条件です。
private void listLocal_ItemDrag(object sender, ItemDragEventArgs e)
{
if (_currAddress == null) return; //if the current address is My Computer
_DraggedItems.Clear();
foreach (ListViewItem item in listLocal.SelectedItems)
{
_DraggedItems.Add((ListViewItem)item.Clone());
}
// if ( some condition ) call the same listview **listLocal.DoDragDrop**
listLocal.DoDragDrop(e.Item, DragDropEffects.All);
// else call the other listview
listView1.DoDragDrop(e.Item, DragDropEffects.All);
}
また、リストビューのDragDropが起動したときに、ドラッグされたアイテムが同じリストビューからのものかどうかを確認する条件が必要です。
private void listView1_DragDrop(object sender, DragEventArgs e)
{
Point p = listView1.PointToClient(MousePosition);
ListViewItem targetItem = listView1.GetItemAt(p.X, p.Y);
// if ( some condition )
//here i need to check if the dragged item came from the same listview or not
{
if (targetItem == null)
{
PreSend(currAddress); //send to the current address
}
else
{
PreSend(targetItem.ToolTipText); //send to the target folder
}
return;
}
//otherwise
if (targetItem == null) { return; } //if dropped in the same folder return
if ((e.Effect & DragDropEffects.Move) == DragDropEffects.Move)
{
Thread thMove = new Thread(unused => PasteFromMove(targetItem.ToolTipText, DraggedItems));
thMove.Start();
}
else
{
Thread thCopy = new Thread(unused => PasteFromCopy(targetItem.ToolTipText, DraggedItems));
thCopy.Start();
}
}