Did you create the items you are sorting? If so, just make your class
implement the IComparable interface. You can have a property that
indicates whether or not sorting should be case insensitive then just
provide the logic in the CompareTo method of the IComparable interface.
If you don't have control of the items you are sorting, then you need
to make a separate class called MyItemComparer (for example) that
implements the IComparer interface and put the compare logic there.
Then use an instance of that class when you create the SortedList.
When creating a SortedList you would instantiate the class like this:
Dim MyComparer As New MyItemComparer(True) 'True = sort case
sensitive
Dim MySortedList As New SortedList(MyComparer)
Here is a example (sorting logic not provided, watch for word wrap):
Public Class MyItemComparer
Implements IComparer
Private bSortCaseSensitive As Boolean
Public Sub New(Optional ByVal casesensitive As Boolean = False)
MyBase.New()
bSortCaseSensitive = casesensitive
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer Implements System.Collections.IComparer.Compare
'Return the comparison result of the two objects
If bSortCaseSensitive Then
'Compare x and y in a case sensitive fashion and return
result
Else
'Compare x and y in a case insensitive fashion and return
result
End If
End Function
End Class
Of course, you would adjust the code to compare your items correctly.
The Compare function should return -1 if the first item is less than
the second, 0 if they are equal, and 1 if the first item is greater
than the second. Check the docs for the IComparer interface to make
sure.