各位老大, 我创建了一个 listView1, listView1.View = detail, 我的 listView1 中有若干个 ListViewItem,
我怎么能 每个 ListViewItem 之间的拖动,比如我把 listViewItem1 拖到 listViewItem3 之后,用鼠标拖动
我怎么能 每个 ListViewItem 之间的拖动,比如我把 listViewItem1 拖到 listViewItem3 之后,用鼠标拖动
解决方案 »
- public IVData(IContainer Container) : this()解疑
- 在winform的resx文件中添加imageliststreamer
- 请问关于C# StreamReader.Readline行标志
- “应用”这个按钮功能如何实现,在线等
- 关于gridview中radiobutton列的焦点问题
- Performance Tools
- 智能五子棋
- 管理软件权限开发思路
- 当同时存在多个toolTip的时候,如何决定到底用哪一个?
- 类似 VB.Net 中的RaiseEvent语句 的C#用法
- 验证email的正则对吗?帮我看一下,谢谢"(?<=<a href=mailto:)[^~]*?(?=>)"
- 做个大型网站,你选择C#还是j2ee?
using System.Drawing;
using System.Collections;
using System.Windows.Forms;namespace Bol.WinControls
{
public class ListViewEx : ListView
{
private const string REORDER = "Reorder"; private bool allowRowReorder = true;
public bool AllowRowReorder
{
get
{
return this.allowRowReorder;
}
set
{
this.allowRowReorder = value;
base.AllowDrop = value;
}
} public new SortOrder Sorting
{
get
{
return SortOrder.None;
}
set
{
base.Sorting = SortOrder.None;
}
} public ListViewEx()
: base()
{
this.AllowRowReorder = true;
} protected override void OnDragDrop(DragEventArgs e)
{
base.OnDragDrop(e);
if(!this.AllowRowReorder)
{
return;
}
if(base.SelectedItems.Count==0)
{
return;
}
Point cp = base.PointToClient(new Point(e.X, e.Y));
ListViewItem dragToItem = base.GetItemAt(cp.X, cp.Y);
if(dragToItem==null)
{
return;
}
int dropIndex = dragToItem.Index;
if(dropIndex>base.SelectedItems[0].Index)
{
dropIndex++;
}
ArrayList insertItems =
new ArrayList(base.SelectedItems.Count);
foreach(ListViewItem item in base.SelectedItems)
{
insertItems.Add(item.Clone());
}
for(int i=insertItems.Count-1;i>=0;i--)
{
ListViewItem insertItem =
(ListViewItem)insertItems[i];
base.Items.Insert(dropIndex, insertItem);
}
foreach(ListViewItem removeItem in base.SelectedItems)
{
base.Items.Remove(removeItem);
}
}
protected override void OnDragOver(DragEventArgs e)
{
if(!this.AllowRowReorder)
{
e.Effect = DragDropEffects.None;
return;
}
if(!e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.None;
return;
}
Point cp = base.PointToClient(new Point(e.X, e.Y));
ListViewItem hoverItem = base.GetItemAt(cp.X, cp.Y);
if(hoverItem==null)
{
e.Effect = DragDropEffects.None;
return;
}
foreach(ListViewItem moveItem in base.SelectedItems)
{
if(moveItem.Index==hoverItem.Index)
{
e.Effect = DragDropEffects.None;
hoverItem.EnsureVisible();
return;
}
}
base.OnDragOver(e);
String text = (String)e.Data.GetData(REORDER.GetType());
if(text.CompareTo(REORDER)==0)
{
e.Effect = DragDropEffects.Move;
hoverItem.EnsureVisible();
}
else
{
e.Effect = DragDropEffects.None;
}
} protected override void OnDragEnter(DragEventArgs e)
{
base.OnDragEnter(e);
if(!this.AllowRowReorder)
{
e.Effect = DragDropEffects.None;
return;
}
if(!e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.None;
return;
}
base.OnDragEnter(e);
String text = (String)e.Data.GetData(REORDER.GetType());
if(text.CompareTo(REORDER)==0)
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
} protected override void OnItemDrag(ItemDragEventArgs e)
{
base.OnItemDrag(e);
if(!this.AllowRowReorder)
{
return;
}
base.DoDragDrop(REORDER, DragDropEffects.Move);
}
}
}
这个是我在codeproject上拷贝来的.呵呵。不是自己写的
最近也是一直在搞ui
希望大家可以一起研究