C# ListView添加DragDrop
先建立好ListView,ImageList,
然后编写一个比较类
在就是添加DragDrop事件了
具体实现看代码吧
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- InitializeListView();
- }
- // 初始化listView1.
- private void InitializeListView()
- {
- listView1.ListViewItemSorter = new ListViewIndexComparer();
- //初始化插入标记
- listView1.InsertionMark.Color = Color.Red;
- //
- listView1.AllowDrop = true;
- }
- // 当一个项目拖拽是启动拖拽操作
- private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
- {
- listView1.DoDragDrop(e.Item, DragDropEffects.Move);
- }
- private void listView1_DragEnter(object sender, DragEventArgs e)
- {
- e.Effect = e.AllowedEffect;
- }
- //像拖拽项目一样移动插入标记
- private void listView1_DragOver(object sender, DragEventArgs e)
- {
- // 获得鼠标坐标
- Point point = listView1.PointToClient(new Point(e.X, e.Y));
- // 返回离鼠标最近的项目的索引
- int index = listView1.InsertionMark.NearestIndex(point);
- // 确定光标不在拖拽项目上
- if (index > -1)
- {
- Rectangle itemBounds = listView1.GetItemRect(index);
- if (point.X > itemBounds.Left + (itemBounds.Width / 2))
- {
- listView1.InsertionMark.AppearsAfterItem = true;
- }
- else
- {
- listView1.InsertionMark.AppearsAfterItem = false;
- }
- }
- listView1.InsertionMark.Index = index;
- }
- // 当鼠标离开控件时移除插入标记
- private void listView1_DragLeave(object sender, EventArgs e)
- {
- listView1.InsertionMark.Index = -1;
- }
- // 将项目移到插入标记所在的位置
- private void listView1_DragDrop(object sender, DragEventArgs e)
- {
- // 返回插入标记的索引值
- int index = listView1.InsertionMark.Index;
- // 如果插入标记不可见,则退出.
- if (index == -1)
- {
- return;
- }
- // 如果插入标记在项目的右面,使目标索引值加一
- if (listView1.InsertionMark.AppearsAfterItem)
- {
- index++;
- }
- // 返回拖拽项
- ListViewItem item = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
- //在目标索引位置插入一个拖拽项目的副本
- listView1.Items.Insert(index, (ListViewItem)item.Clone());
- // 移除拖拽项目的原文件
- listView1.Items.Remove(item);
- }
- // 对ListView里的各项根据索引进行排序
- private class ListViewIndexComparer : System.Collections.IComparer
- {
- public int Compare(object x, object y)
- {
- return ((ListViewItem)x).Index - ((ListViewItem)y).Index;
- }
- }
- }
- http://blog.csdn.net/lilongherolilong/article/details/6689109
转载于:https://www.cnblogs.com/Echo529/p/6382090.html
C# ListView添加DragDrop相关推荐
- ListView 添加头部 和尾部 布局 (addHeaderView 和 addFooterView)
ListView 添加头部 和尾部 布局 其实很简单 ,listview 暴露的有方法addHeaderView 和 addFooterView 从源码里面可以看到, addHeaderView 和 ...
- Flutter开发之ListView添加HeaderView和FooterView-2(39)
参考文章:RecyclerView添加HeaderView和FooterView 接着Flutter开发之ListView添加HeaderView和FooterView-1 继续研究. 通过Recyc ...
- Flutter开发之ListView添加HeaderView和FooterView(38)
参考文章:Flutter ListView如何添加HeaderView和FooterView flutter的ListView添加HeaderView和FooterView使用CustomScroll ...
- ListView添加项目带序列
ListView添加项目带序列 function AddSelItems(listview1:TListView;ListView2:TListView):Boolean; var s: stri ...
- android listview remove 动画,给Android ListView添加删除item动画
给Android ListView添加删除item动画 给listview删除一个item的时候加上一个折叠动画,感觉效果会好一点. 步骤是当删除一个view,先用动画把view的高度改变,看上去就是 ...
- ListView隐藏右侧滚动条,listview去掉分割线,自定义分割线,ListView添加HeaderView和FooterView
ListView添加HeaderView和FooterView View headerView = LayoutInflater.from(AddwcrrActivity.this).inflate( ...
- delphi listview 添加数据 慢_ListView 的缓存机制
一.前言 ListView 作为一个 Android 5.x 之前的一个用于显示数据列表的控件,或许在今天都已经被 RecyclerView 完全替代,但是其中的缓存机制仍然值得我们去了解,对后面学习 ...
- listview winfrom 表头_c# listview添加表头
2012-03-23 11:37 C# ListView Controlusing System.Windows.Forms; ListView控件添加表头: ColumnHeader h1 = ne ...
- Android ListView添加头部和尾部
ListView添加头部和尾部: 头部布局:addHeaderView 尾部布局:addFooterView 使用java代码: //添加头部final View header = View.infl ...
最新文章
- Office 2010 中的 UI 扩展性
- Okhttp-interceptor源码分析,快上车!
- 《Apache Kafka实战》读书笔记-调优Kafka集群
- jzoj3500-物语【最短路】
- Windows 下安装 laravel框架
- 公司聚餐完毕,明日启程回家过年
- Understanding ASP.NET Validation Techniques
- sqlplus connect oracle
- Android源码目录结构
- ca 手机抓包_抓包安卓7以上ca证书安装方法
- 网易 UI 自动化工具 Airtest
- 嵌入式开发有必要学习python吗?
- STM32 CAN总线故障检测功能的使用
- 如何将整个网页变成灰色
- 4.26学习记录 AWS 和 DNS
- EventBus总结
- StoreFront配置本地安装Receiver客户端
- opencv的图片处理:缩小尺寸为原图的一半【自己练习存档,没有参考价值,多看其他大神代码,谢谢】
- SpreadJS 16.0.3 Crack
- Windows8开发指南(16)开发基于Windows8的第一个metro界面C++程序
热门文章
- ppct各代表什么_开关背面L、L1、L2各代表什么?火线,零线,地线怎样接?
- 网络营销外包——网站搜索框设计不同人群网络营销外包有不同设计
- java sessionstate_在Java Web开发中自定义Session
- 数据处理_流数据处理利器
- 蓝牙怎么实现传输的_不知道手机蓝牙有啥用?1分钟带你了解蓝牙这6种用法!涨知识啦...
- 文件格式和扩展名不匹配.文件可能已损坏_自媒体良器:音频文件批处理,FFmpeg一行搞定!果断收藏...
- ironbot智能编程机器人_视频 | 多模式编程机器人,“程序猿”培养从小抓起
- MongoDB 3.0 WiredTiger Compression and Performance
- mysql 避免使用NULL字段
- numpy vsplit