Según la MSDN, el tipo
System.Collections.Generic.SortedSet(Of T) está disponible a partir de .NET Framework v4.0.
Puedes cambiar la versión de .NET Framework en las opciones del proyecto de Visual Studio. Si por el motivo que sea no puedes trabajar bajo .NET Framework v4.0, entonces como ya te mencioné puedes utilizar el tipo genérico
System.Collections.Generic.List(Of T):
Dim integerList As New List(Of Integer)
For Each item As Object In Me.ListBox1.Items
integerList.Add(CInt(item))
Next item
integerList.Sort(Comparer(Of Integer).Default)
For Each value As Integer In integerList
Me.ListBox1.Items.Add(value)
Next value
Bueno la verdad no supe en donde poner el código.
Te lo voy a poner bien facil.
1. Añade este módulo a tu código fuente:
<HideModuleName>
Public Module ListBoxExtensions
<DebuggerStepThrough>
<Extension>
Public Sub Sort(Of T)(ByVal sender As ListBox)
ListBoxExtensions.Sort(Of T)(sender, Comparer(Of T).Default)
End Sub
<DebuggerStepThrough>
<Extension>
Public Sub Sort(Of T)(ByVal sender As ListBox, ByVal comparer As IComparer(Of T))
Dim itemList As New List(Of T)
For Each item As T In sender.Items
itemList.Add(item)
Next item
itemList.Sort(comparer)
sender.SuspendLayout()
sender.Items.Clear()
For Each item As T In itemList
sender.Items.Add(item)
Next item
sender.ResumeLayout()
End Sub
End Module
2. Cuando quieras ordenar los elementos del
ListBox, simplemente debes llamar al método
Sort:
Me.ListBox1.Sort(Of Integer) ' Para enteros.
...O si necesitas un ordenamiento de Strings:
Me.ListBox1.Sort(Of String) ' Para texto.
PD: Lo siento, sin querer reemplacé el contenido de tu último mensaje, lo he podido recuperar pero se perdió el formato que le diste.
Saludos