I'm trying to Drag from listView1 and drop on listLocal which both of them are ListView
It's a file transfer application between client and server, the application shows small local file explorer listLocal and remote file explorer listView1.
so when I drop the items from listView1 to listLocal and the pointer points on an item[Folder] it should be highlighted item.Selected = true
.
but it doesn't work, I tried to do listLocal.Focus
and listLocal.Select
still not working, how could I make it work ?
note : when I used item.BackColor = Color.RoyalBlue;
it worked, but it doesn't highlight the icon.
private void listLocal_DragOver(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(typeof(ListViewItem))) return;
Point p = listLocal.PointToClient(MousePosition);
ListViewItem targetItem = listLocal.GetItemAt(p.X, p.Y);
if (targetItem != null) //if dropping on a target item
{
targetItem.Selected = true;
if (targetItem.SubItems.Count > 1) e.Effect = DragDropEffects.None;//if IsFile
else e.Effect = DragDropEffects.Copy;
return;
}
foreach (ListViewItem item in listLocal.Items) item.Selected = false; //if dragging into current address
e.Effect = DragDropEffects.Copy;
}