|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Invert an Arraylist.Sort()Hi List, I have an arraylist of objects. I have created my own IComparable
in the object to return the sort on datetime. This works great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05 before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!) for my application. Public Function CompareTo(ByVal obj As Object) As Integer Implements + _ System.IComparable.CompareTo If TypeOf obj Is glcobject Then Dim tmp As glcobject = DirectCast(obj, glcobject) Return m_datetime.CompareTo(tmp.m_datetime) End If End Function ??? Thanks! Derek Maybe create a property which tells your object which way to sort. Then in
CompareTo look at that property, and return the appropriate result. Show quoteHide quote "Derek Martin" <dmj2195@DONTSPAMMEokstateDOT.edu> wrote in message news:%23NGbTRtOFHA.3928@TK2MSFTNGP09.phx.gbl... > Hi List, I have an arraylist of objects. I have created my own > IComparable in the object to return the sort on datetime. This works > great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05 > before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!) > for my application. > > Public Function CompareTo(ByVal obj As Object) As Integer Implements + _ > System.IComparable.CompareTo > If TypeOf obj Is glcobject Then > Dim tmp As glcobject = DirectCast(obj, glcobject) > Return m_datetime.CompareTo(tmp.m_datetime) > End If > End Function > > ??? > > Thanks! > Derek > Call Sort, and then ArrayList.Reverse.
Show quoteHide quote "Derek Martin" <dmj2195@DONTSPAMMEokstateDOT.edu> wrote in message news:%23NGbTRtOFHA.3928@TK2MSFTNGP09.phx.gbl... > Hi List, I have an arraylist of objects. I have created my own > IComparable in the object to return the sort on datetime. This works > great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05 > before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!) > for my application. > > Public Function CompareTo(ByVal obj As Object) As Integer Implements + _ > System.IComparable.CompareTo > If TypeOf obj Is glcobject Then > Dim tmp As glcobject = DirectCast(obj, glcobject) > Return m_datetime.CompareTo(tmp.m_datetime) > End If > End Function > > ??? > > Thanks! > Derek > Ooooh - good idea!!!! Thanks Russell...
Derek Show quoteHide quote "Russell Jones" <arj1@nospam.northstate.net> wrote in message news:uSInuXtOFHA.1176@TK2MSFTNGP12.phx.gbl... > Call Sort, and then ArrayList.Reverse. > > "Derek Martin" <dmj2195@DONTSPAMMEokstateDOT.edu> wrote in message > news:%23NGbTRtOFHA.3928@TK2MSFTNGP09.phx.gbl... >> Hi List, I have an arraylist of objects. I have created my own >> IComparable in the object to return the sort on datetime. This works >> great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05 >> before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!) >> for my application. >> >> Public Function CompareTo(ByVal obj As Object) As Integer Implements + _ >> System.IComparable.CompareTo >> If TypeOf obj Is glcobject Then >> Dim tmp As glcobject = DirectCast(obj, glcobject) >> Return m_datetime.CompareTo(tmp.m_datetime) >> End If >> End Function >> >> ??? >> >> Thanks! >> Derek >> > > If m_ascending Then
If Not v_CaseSensitive Then Return New CaseInsensitiveComparer().Compare(x, y) Else Return New Comparer(ci).Compare(x, y) Else If Not v_CaseSensitive Then Return New CaseInsensitiveComparer().Compare(y, x) Else Return New Comparer(ci).Compare(y, x) End If Show quoteHide quote "Derek Martin" wrote: > Ooooh - good idea!!!! Thanks Russell... > > Derek > > "Russell Jones" <arj1@nospam.northstate.net> wrote in message > news:uSInuXtOFHA.1176@TK2MSFTNGP12.phx.gbl... > > Call Sort, and then ArrayList.Reverse. > > > > "Derek Martin" <dmj2195@DONTSPAMMEokstateDOT.edu> wrote in message > > news:%23NGbTRtOFHA.3928@TK2MSFTNGP09.phx.gbl... > >> Hi List, I have an arraylist of objects. I have created my own > >> IComparable in the object to return the sort on datetime. This works > >> great! Now, I'd like to invert the sort. Currently, it gives me 4/1/05 > >> before 4/5/05 (good), but I'd like to have 4/5/05 before 4/1/05 (better!) > >> for my application. > >> > >> Public Function CompareTo(ByVal obj As Object) As Integer Implements + _ > >> System.IComparable.CompareTo > >> If TypeOf obj Is glcobject Then > >> Dim tmp As glcobject = DirectCast(obj, glcobject) > >> Return m_datetime.CompareTo(tmp.m_datetime) > >> End If > >> End Function > >> > >> ??? > >> > >> Thanks! > >> Derek > >> > > > > > > >
Please do NOT sign the VB.COM petition
What am I doing wrong - Trying to update Option Strict disallows late binding, need to update code Setup project registery values with app install folder in them Set textbox1.enabled = false inside a module? How to create a zoom feature in Vb.Net '' Could not be set on property 'Items' - Error Icons in a class library Excel In VB.net Collection Class Serialization |
|||||||||||||||||||||||