简体   繁体   中英

how to highlight an item in listview?

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;
    }

将HideSelection属性设置为False

You may try to handle the DragOver method. or have a look at example from microsoft: MSDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM