如何突出在列表视图中的项目? [英] how to highlight an item in listview?

查看:141
本文介绍了如何突出在列表视图中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ListView1的拖动和listLocal 这两者都是的ListView 结果下降
这是客户端和服务器之间的文件传输应用程序,该应用程序显示小地方的文件浏览器的 listLocal 和远程文件浏览器的 ListView1的。结果,所以当我把项目从<强> ListView1的为 listLocal 并在项目上的指针指向[文件夹]应当强调 item.Selected = TRUE
结果
但它不工作,我试图做 listLocal.Focus listLocal.Select 仍然没有工作,怎么可能我使它工作?

请注意:当我用 item.BackColor = Color.RoyalBlue; 它的工作,但它并不突出的图标

 私人无效listLocal_DragOver(对象发件人,DragEventArgs E)
   {
      如果(e.Data.GetData present(typeof运算(ListViewItem的))!)回报;
      点P = listLocal.PointToClient(MousePosition);
      ListViewItem的targetItem = listLocal.GetItemAt(p.X,p.Y);
      如果(targetItem!= NULL)//如果放弃对目标项目
      {
        targetItem.Selected = TRUE;
        如果(targetItem.SubItems.Count→1)e.Effect = DragDropEffects.None; //如果ISFILE
        否则e.Effect = DragDropEffects.Copy;
        返回;
      }
      的foreach(在listLocal.Items ListViewItem的项目)item.Selected = FALSE; //如果拖到当前地址
      e.Effect = DragDropEffects.Copy;
    }


解决方案

在HideSelection属性设置为False

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

解决方案

Set the HideSelection property to False

这篇关于如何突出在列表视图中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆