I have a ListView (WinForms) in which i want to move items up and down with the click of a button. The items to be moved are the ones who are checked. So if item 2, 6 and 9 are
Just to complete the @Jason Larkes answer to make it support "move down" properly, add this right before the foreach in the MoveListViewItems function he provided:
ListViewItem[] itemsToBeMoved = sender.SelectedItems.Cast().ToArray();
IEnumerable itemsToBeMovedEnum;
if (direction == MoveDirection.Down)
itemsToBeMovedEnum = itemsToBeMoved.Reverse();
else
itemsToBeMovedEnum = itemsToBeMoved;
and then iterate using:
foreach (ListViewItem item in itemsTobemovedEnum)
instead of the original foreach.
Works like a charm. @EClaesson - I hope this overcomes the issue you wrote about in the comments.