title: Sorting contents of a listbox
body: <p>I'm using the following code to add items to a listbox:</p>
  
  <pre><code>Dim i As Integer = 0
  Dim temp As String
  
  ListBox2.Items.Clear()
  While i &lt;= 9
      temp = Str(final_average(i)) + "        " + Str(i + 1) + "             " + Str(cals(i))
      ListBox2.Items.Add(temp)
      i = i + 1
  End While
  </code></pre>
  
  <p>I want to sort this using the <code>average</code> or <code>final_average(i)</code>, but the following code doesn't seem to work:</p>
  
  <pre><code>Dim arr(ListBox2.Items.Count - 1) As Object
  
  ListBox2.Items.CopyTo(arr, 0)
  Array.Sort(arr)
  ListBox2.Items.Clear()
  ListBox2.Items.AddRange(arr)
  </code></pre>
  
  <p>How do I sort the contents of the listbox?</p>
  
  <p><em>(Note: This is not homework but part of a bigger project).</em></p>