先建立好ListView,ImageList,
然后编写一个比较类
在就是添加DragDrop事件了
具体实现看代码吧

    1. public partial class Form1 : Form
    2. {
    3. public Form1()
    4. {
    5. InitializeComponent();
    6. InitializeListView();
    7. }
    8. // 初始化listView1.
    9. private void InitializeListView()
    10. {
    11. listView1.ListViewItemSorter = new ListViewIndexComparer();
    12. //初始化插入标记
    13. listView1.InsertionMark.Color = Color.Red;
    14. //
    15. listView1.AllowDrop = true;
    16. }
    17. // 当一个项目拖拽是启动拖拽操作
    18. private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
    19. {
    20. listView1.DoDragDrop(e.Item, DragDropEffects.Move);
    21. }
    22. private void listView1_DragEnter(object sender, DragEventArgs e)
    23. {
    24. e.Effect = e.AllowedEffect;
    25. }
    26. //像拖拽项目一样移动插入标记
    27. private void listView1_DragOver(object sender, DragEventArgs e)
    28. {
    29. // 获得鼠标坐标
    30. Point point = listView1.PointToClient(new Point(e.X, e.Y));
    31. // 返回离鼠标最近的项目的索引
    32. int index = listView1.InsertionMark.NearestIndex(point);
    33. // 确定光标不在拖拽项目上
    34. if (index > -1)
    35. {
    36. Rectangle itemBounds = listView1.GetItemRect(index);
    37. if (point.X > itemBounds.Left + (itemBounds.Width / 2))
    38. {
    39. listView1.InsertionMark.AppearsAfterItem = true;
    40. }
    41. else
    42. {
    43. listView1.InsertionMark.AppearsAfterItem = false;
    44. }
    45. }
    46. listView1.InsertionMark.Index = index;
    47. }
    48. // 当鼠标离开控件时移除插入标记
    49. private void listView1_DragLeave(object sender, EventArgs e)
    50. {
    51. listView1.InsertionMark.Index = -1;
    52. }
    53. // 将项目移到插入标记所在的位置
    54. private void listView1_DragDrop(object sender, DragEventArgs e)
    55. {
    56. // 返回插入标记的索引值
    57. int index = listView1.InsertionMark.Index;
    58. // 如果插入标记不可见,则退出.
    59. if (index == -1)
    60. {
    61. return;
    62. }
    63. // 如果插入标记在项目的右面,使目标索引值加一
    64. if (listView1.InsertionMark.AppearsAfterItem)
    65. {
    66. index++;
    67. }
    68. // 返回拖拽项
    69. ListViewItem item = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
    70. //在目标索引位置插入一个拖拽项目的副本
    71. listView1.Items.Insert(index, (ListViewItem)item.Clone());
    72. // 移除拖拽项目的原文件
    73. listView1.Items.Remove(item);
    74. }
    75. // 对ListView里的各项根据索引进行排序
    76. private class ListViewIndexComparer : System.Collections.IComparer
    77. {
    78. public int Compare(object x, object y)
    79. {
    80. return ((ListViewItem)x).Index - ((ListViewItem)y).Index;
    81. }
    82. }
    83. }  
      1. http://blog.csdn.net/lilongherolilong/article/details/6689109

C# ListView添加DragDrop的更多相关文章

  1. 仿喜马拉雅实现ListView添加头布局和脚布局

     ListView添加头布局和脚布局 之前学习喜马拉雅的时候做的一个小Demo,贴出来,供大家学习参考: 如果我们当前的页面有多个接口.多种布局的话,我们一般的选择无非就是1.多布局:2.各种复杂滑动 ...

  2. ListView添加项目带序列

    ListView添加项目带序列     function AddSelItems(listview1:TListView;ListView2:TListView):Boolean;var  s: st ...

  3. 为ListView添加头和脚

      转自:https://software.intel.com/zh-cn/blogs/2014/12/15/android-listview-addheaderview-addfooterview ...

  4. 自定义listView添加滑动删除功能

    今天研究了一下android里面的手势,结合昨天学习的自定义View,做了一个自定义的listview,继承自listView,添加了条目的滑动手势操作,滑动后出现一个删除按钮,点击删除按钮,触发一个 ...

  5. Android之listview添加数据篇

    一.ListView: 1. ListView通常有两个职责: 1.向布局填充数据 2.处理选择点击等操作 2.ListView的创建需要3个元素: 1. ListView中的每一列的View. 2. ...

  6. Android在listview添加checkbox实现单选多选操作问题(转)

    转自:http://yangshen998.iteye.com/blog/1310183 在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上 ...

  7. 【WinForm】线程中向listview添加数据

    在使用listview的时候,因为处理的数据较多,为防止在处理数据时出现假死的状态出现卡的情况,我们使用委托进行处理添加数据 定义委托 private delegate void AddListVie ...

  8. Android在listview添加checkbox实现单选多选操作问题

    android根据View的不同状态更换不同的背景http://www.eoeandroid.com/thread-198029-1-1.html android 模仿朋友网推出的菜单效果[改进版]h ...

  9. ListView添加图片文字项

    1)listview 控件 结合 imagelist 控件 实现类似效果. 2)添加 imagelist 控件 images 属性,点击后面的... 添加相应图片. 3)点listview,查看其属性 ...

随机推荐

  1. 【NOIP2016提高A组模拟8.14】疯狂的火神

    题目 火神为了检验zone的力量,他决定单挑n个人. 由于火神训练时间有限,最多只有t分钟,所以他可以选择一部分人来单挑,由于有丽子的帮助,他得到了每个人特定的价值,每个人的价值由一个三元组(a,b, ...

  2. Spring AOP expose-proxy

    写在前面 expose-proxy.为是否暴露当前代理对象为ThreadLocal模式. SpringAOP对于最外层的函数只拦截public方法,不拦截protected和private方法(后续讲 ...

  3. Element ui 中的表单提交按钮多次点击bug修复

  4. Internet History, Technology, and Security(week5)——Technology: Internets and Packets

    前言: 之前都在学习Internet的历史,从这周开始,进入到了Internet技术的学习. Layer1: Link Introduction / The Link Layer 80年代之前,主流网 ...

  5. es之得分(加权)

    随着应用程序的增长,提高搜索质量的需求也进一步增大.我们把它叫做搜索体验.我们需要知道什么对用户更重要,关注用户如何使用搜索功能.这导致不同的结论,例如,有些文档比其他的更重要,或特定查询需强调一个字 ...

  6. 设计模式-Runoob:设计模式

    ylbtech-设计模式-Runoob:设计模式 1.返回顶部 1. 设计模式 设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用.设计模式是软件开发 ...

  7. 用Vue来实现音乐播放器(十五):处理得到的歌手数据

    之前得到的歌手数据是用forEach遍历添加的  没有顺序性  我们希望得到的数据是title:"热门"的数据在最上面  title为字母的数据按字母从低到高顺序排列 var ho ...

  8. linux 互斥量

    互斥量(mutex)从本质上来说是一把锁,在访问共享资源前对互斥量进行加锁,在访问完后释放互斥量上的锁. 对互斥量进行加锁以后,任何其他试图再次对互斥量加锁的线程都将会被阻塞直到当前线程释放该互斥锁. ...

  9. Pandas 50题练习

    f行的age改为1. df.loc['f', 'age'] = 1.5 这样比 df.loc['f']['age'] 好 计算df中每个种类animal的数量 df['animal'].value_c ...

  10. 测开之路一百:jquery引用、语法、事件

    工作中一般会使用jquery代替js,jquery官网:https://jquery.com/ 引用jquery: 第一种方式:下载引用: jquery下载官网:https://jquery.com/ ...