title: How to swap indexes in a list of objects
body: <p>So I have a class as seen below:</p>
  
  <pre><code>Public Class parameters
      Public Property test As String
      Public Property test_type As String
      Public Property user_test_name As String
      Public Property meas As String
      Public Property spec_min As String
      Public Property spec_max As String
      Public Property spec_unit As String
  
      Public Overrides Function ToString() As String
          Return user_test_name
      End Function
  End Class
  </code></pre>
  
  <p>I have written each object in a list of objects and written them to a listbox. </p>
  
  <p>I woould like to move the items in the list box up and down and I have done so by the following code successfully:</p>
  
  <pre><code>Private Sub up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles up.Click
      'Move up
  
      'Make sure our item is not the first one on the list.
      If ListBox1.SelectedIndex &gt; 0 Then
  
          Dim I = ListBox1.SelectedIndex - 1
          ListBox1.Items.Insert(I, ListBox1.SelectedItem)
          ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
          ListBox1.SelectedIndex = I
      End If
  
  End Sub
  
  Private Sub down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles down.Click
  
      'Move down
  
      'Make sure our item is not the last one on the list.
      If ListBox1.SelectedIndex &lt; ListBox1.Items.Count - 1 Then
          'Insert places items above the index you supply, since we want
          'to move it down the list we have to do + 2
          Dim I = ListBox1.SelectedIndex + 2
          ListBox1.Items.Insert(I, ListBox1.SelectedItem)
          ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
          ListBox1.SelectedIndex = I - 1
  
      End If
  End Sub
  </code></pre>
  
  <p>But I would also like the actual indexes in the list to change as the selected item moves up or down. This way when im exporting the file I can keep the order that the user has selected. Please advise?</p>