I recently had the pleasure of sorting my list of hotel objects (whose glorious dropdowns you will hopefully soon see on our cheap hotels booking site: http://reservations.hotelscheap.org) and it was indeed a pleasure.
First, you start by creating a class for your specific sort. In this case I'm sorting the list of hotels alphabetically on their name. Each hotel has, naturally, a string property called hotelname. Since string has a built in function called compare (and many types do have built-in compare functions),
Public Class CompareHotelName
Implements IComparer(Of hotel)
Public Function Compare( _
ByVal x As hotel, ByVal y As hotel) _
As Integer _
Implements System.Collections.Generic.IComparer(Of hotel).Compare
Return String.Compare(x.hotelname, y.hotelname)
End Function
End Class
and then, since I'm using a new generics list (of hotel), I simply call the sort method, and pass in my comparer: (and I call reverse after sorting, to reverse the order)
hotellist.Sort(New CompareHotelName)
If spec.SortOrder = SortOrder.descending Then
hotellist.Reverse()
End If