Quote Originally Posted by JimAvanti View Post
Is there any reason you are against sorting in-place? does it take longer to sort that way?
I haven't tested this scenario specifically but calling Add repeatedly to add multiple items to a ListView gets exponentially slower because the control redraws after each Add call. I'd expect the same to happen at least once - possibly twice - when you call Remove and Insert. If you really wanted to swap data between items then I'd suggest writing a method or two to do it. You should already have the items themselves because you would have to have compared them to determine that they need to be swapped, so you shouldn't need to work with indexes:
vb.net Code:
  1. Private Sub SwapListViewItems(item1 As ListViewItem, item2 As ListViewItem)
  2.     Dim text As String
  3.  
  4.     For i = 0 To item1.SubItems.Count - 1
  5.         Dim subitem1 = item1.SubItems(i)
  6.         Dim subitem2 = item2.SubItems(i)
  7.  
  8.         text = subitem1.Text
  9.         subitem1.Text = subitem2.Text
  10.         subitem2.Text = text
  11.     Next
  12. End Sub
If you must use indexes:
vb.net Code:
  1. Private Sub SwapListViewItems(index1 As Integer)
  2.     Dim item1 = ListView1.Items(index1)
  3.     Dim item2 = ListView1.Items(index1 + 1)
  4.  
  5.     Dim text As String
  6.  
  7.     For i = 0 To item1.SubItems.Count - 1
  8.         Dim subitem1 = item1.SubItems(i)
  9.         Dim subitem2 = item2.SubItems(i)
  10.  
  11.         text = subitem1.Text
  12.         subitem1.Text = subitem2.Text
  13.         subitem2.Text = text
  14.     Next
  15. End Sub