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

[csharp] view plaincopy
  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

转载于:https://www.cnblogs.com/Echo529/p/6382090.html

C# ListView添加DragDrop相关推荐

  1. ListView 添加头部 和尾部 布局 (addHeaderView 和 addFooterView)

    ListView 添加头部 和尾部 布局  其实很简单 ,listview 暴露的有方法addHeaderView 和 addFooterView 从源码里面可以看到, addHeaderView 和 ...

  2. Flutter开发之ListView添加HeaderView和FooterView-2(39)

    参考文章:RecyclerView添加HeaderView和FooterView 接着Flutter开发之ListView添加HeaderView和FooterView-1 继续研究. 通过Recyc ...

  3. Flutter开发之ListView添加HeaderView和FooterView(38)

    参考文章:Flutter ListView如何添加HeaderView和FooterView flutter的ListView添加HeaderView和FooterView使用CustomScroll ...

  4. ListView添加项目带序列

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

  5. android listview remove 动画,给Android ListView添加删除item动画

    给Android ListView添加删除item动画 给listview删除一个item的时候加上一个折叠动画,感觉效果会好一点. 步骤是当删除一个view,先用动画把view的高度改变,看上去就是 ...

  6. ListView隐藏右侧滚动条,listview去掉分割线,自定义分割线,ListView添加HeaderView和FooterView

    ListView添加HeaderView和FooterView View headerView = LayoutInflater.from(AddwcrrActivity.this).inflate( ...

  7. delphi listview 添加数据 慢_ListView 的缓存机制

    一.前言 ListView 作为一个 Android 5.x 之前的一个用于显示数据列表的控件,或许在今天都已经被 RecyclerView 完全替代,但是其中的缓存机制仍然值得我们去了解,对后面学习 ...

  8. listview winfrom 表头_c# listview添加表头

    2012-03-23 11:37 C# ListView Controlusing System.Windows.Forms; ListView控件添加表头: ColumnHeader h1 = ne ...

  9. Android ListView添加头部和尾部

    ListView添加头部和尾部: 头部布局:addHeaderView 尾部布局:addFooterView 使用java代码: //添加头部final View header = View.infl ...

最新文章

  1. Office 2010 中的 UI 扩展性
  2. Okhttp-interceptor源码分析,快上车!
  3. 《Apache Kafka实战》读书笔记-调优Kafka集群
  4. jzoj3500-物语【最短路】
  5. Windows 下安装 laravel框架
  6. 公司聚餐完毕,明日启程回家过年
  7. Understanding ASP.NET Validation Techniques
  8. sqlplus connect oracle
  9. Android源码目录结构
  10. ca 手机抓包_抓包安卓7以上ca证书安装方法
  11. 网易 UI 自动化工具 Airtest
  12. 嵌入式开发有必要学习python吗?
  13. STM32 CAN总线故障检测功能的使用
  14. 如何将整个网页变成灰色
  15. 4.26学习记录 AWS 和 DNS
  16. EventBus总结
  17. StoreFront配置本地安装Receiver客户端
  18. opencv的图片处理:缩小尺寸为原图的一半【自己练习存档,没有参考价值,多看其他大神代码,谢谢】
  19. SpreadJS 16.0.3 Crack
  20. Windows8开发指南(16)开发基于Windows8的第一个metro界面C++程序

热门文章

  1. ppct各代表什么_开关背面L、L1、L2各代表什么?火线,零线,地线怎样接?
  2. 网络营销外包——网站搜索框设计不同人群网络营销外包有不同设计
  3. java sessionstate_在Java Web开发中自定义Session
  4. 数据处理_流数据处理利器
  5. 蓝牙怎么实现传输的_不知道手机蓝牙有啥用?1分钟带你了解蓝牙这6种用法!涨知识啦...
  6. 文件格式和扩展名不匹配.文件可能已损坏_自媒体良器:音频文件批处理,FFmpeg一行搞定!果断收藏...
  7. ironbot智能编程机器人_视频 | 多模式编程机器人,“程序猿”培养从小抓起
  8. MongoDB 3.0 WiredTiger Compression and Performance
  9. mysql 避免使用NULL字段
  10. numpy vsplit