C# Listview Drag and Drop Rows
Ensure that
AllowDragDrop
is set totrue
.Implement handlers for at least these 3 events
private void myList_ItemDrag(object sender, ItemDragEventArgs e) { DoDragDrop(e.Item, DragDropEffects.Link); } private void myList_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Link; } private void myList_DragDrop(object sender, DragEventArgs e) { // do whatever you need to reorder the list. }
Getting the index of the row you dropped onto may look something like:
Point cp = myList.PointToClient(new Point(e.X, e.Y)); ListViewItem dragToItem = myList.GetItemAt(cp.X, cp.Y); int dropIndex = dragToItem.Index;