On Thu, 28 Oct 2004 16:28:29 +0200, John Smith wrote:
Dear Chris,
This approach works if you know which Icomparer instance you want to use
when you construct the SortedList but what if you want to (re) sort an
existing list, say first by name, and later on by birth day?
Thanks,
Sven
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:88****************************@40tude.net... On Thu, 28 Oct 2004 13:22:22 +0200, marc wrote:
a,b and c I can get by using sortedlist, but it has no flexible sorting
The SortedList should meet your needs. The constructor for SortedList is
overloaded to allow you to pass in an IComparer instance. You can create
different classes that implement IComparer for each of your sorting styles
and pass in the appropriate one as needed.
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Perhaps the class that implements IComparer could have a property
indicating the sort order or method. If you change the property, the sort
order changes. I haven't tested it but something like this:
Public Class MySorter
Implements IComparer
Private m_SortOrder As String
Public Property SortOrder() As String
Get
Return m_SortOrder
End Get
Set(ByVal Value As String)
m_SortOrder = Value
End Set
End Property
Public Function Compare(...) As Integer Implements IComparer.Compare
Select Case m_SortOrder
Case "Ascending"
'Code here
Case "Descending"
'Code Here
End Select
End Function
End Class
Dim MySorter As New MyClassThatImplementsIComparer
Dim MyList As New SortedList(MySorter)
' other code
'Need to change sort order:
MySorter.SortOrder = "Descending"
In other words, keep the instance of the sorter around so you can set its
property. The Compare routine in the class checks this property and
compares accordingly
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.