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
C# ListView添加DragDrop的更多相关文章
- 仿喜马拉雅实现ListView添加头布局和脚布局
ListView添加头布局和脚布局 之前学习喜马拉雅的时候做的一个小Demo,贴出来,供大家学习参考: 如果我们当前的页面有多个接口.多种布局的话,我们一般的选择无非就是1.多布局:2.各种复杂滑动 ...
- ListView添加项目带序列
ListView添加项目带序列 function AddSelItems(listview1:TListView;ListView2:TListView):Boolean;var s: st ...
- 为ListView添加头和脚
转自:https://software.intel.com/zh-cn/blogs/2014/12/15/android-listview-addheaderview-addfooterview ...
- 自定义listView添加滑动删除功能
今天研究了一下android里面的手势,结合昨天学习的自定义View,做了一个自定义的listview,继承自listView,添加了条目的滑动手势操作,滑动后出现一个删除按钮,点击删除按钮,触发一个 ...
- Android之listview添加数据篇
一.ListView: 1. ListView通常有两个职责: 1.向布局填充数据 2.处理选择点击等操作 2.ListView的创建需要3个元素: 1. ListView中的每一列的View. 2. ...
- Android在listview添加checkbox实现单选多选操作问题(转)
转自:http://yangshen998.iteye.com/blog/1310183 在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上 ...
- 【WinForm】线程中向listview添加数据
在使用listview的时候,因为处理的数据较多,为防止在处理数据时出现假死的状态出现卡的情况,我们使用委托进行处理添加数据 定义委托 private delegate void AddListVie ...
- Android在listview添加checkbox实现单选多选操作问题
android根据View的不同状态更换不同的背景http://www.eoeandroid.com/thread-198029-1-1.html android 模仿朋友网推出的菜单效果[改进版]h ...
- ListView添加图片文字项
1)listview 控件 结合 imagelist 控件 实现类似效果. 2)添加 imagelist 控件 images 属性,点击后面的... 添加相应图片. 3)点listview,查看其属性 ...
随机推荐
- zabbix监控A主机到B主机的网络质量
采用zabbix自带的icmp ping即可进行监控: 1.安装fping 2.将fping安装后链接到/usr/sbin/fping下,设置组为zabbix; 3.增加监控项:icmpping[ip ...
- 【leetcode】Smallest Rotation with Highest Score
题目如下: Given an array A, we may rotate it by a non-negative integer K so that the array becomes A[K], ...
- django model 操作总结
使用场景 一对一:在某表中创建一行数据时,有一个单选的下拉框(下拉框中的内容被用过一次就消失了).//两个表的数据一一对应 例如:原有含10列数据的一张表保存相关信息,经过一段时间之后,10列无法满足 ...
- which statement is true for the class java.util.ArrayList?
A.集合中的元素是有序的 对 B.集合被保证为不可变的 错 C.集合中的元素被保证为唯一的 错 有序的 所以不唯一 D.集合中的元素使用一个唯一的键来存取 错 没有键 E.集合中的元 ...
- NSDate 那点事
转载自:http://my.oschina.net/yongbin45/blog/150114 NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是N ...
- 【转】SQL Pretty Printer for SSMS 很不错的SQL格式化插件
源地址:https://www.cnblogs.com/leospace/archive/2012/09/04/SQL_Pretty_Printer_for_SSMS.html 写SQL语句或者脚本时 ...
- shell后台进程
建立duplicate_removal.sh文件,内容如下:#!/bin/bashmysql -vvv -u root -p123456 test -e "truncate t_target ...
- Longest Subarray(HDU6602+线段树)
题意 要你找一个最长的区间使得区间内每一个数出现次数都大于等于K. 题解->https://blog.csdn.net/Ratina/article/details/97503663 #incl ...
- HDU 5073 Galaxy (数学)
Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
- 背包&数位dp(8.7)
背包 0/1背包 设dp[i][j]为前i个物品选了j体积的物品的最大价值/方案数 dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j])(最大价值) dp[i][ ...