G
Guest
Hi
Been at this problem for 6 hours now, aka. time to admit my defeat and ask for help ;-
The code thats acting up looks like this
Imports System.ComponentMode
Public Class aktivitetList
Inherits System.Collections.CollectionBas
Private _comparer As New aktivitetListSorte
Default Public ReadOnly Property Item(ByVal idx As Int32) As Aktivite
Ge
If list.Count <= idx OrElse idx < 0 The
Throw New ArgumentException("Index was out of bounds"
End I
Return DirectCast(list.Item(idx), Aktivitet
End Ge
End Propert
Public ReadOnly Property ListSorter() As aktivitetListSorte
Ge
Return _compare
End Ge
End Propert
Public Function Add(ByVal aktivitet As Aktivitet) As Int3
Return list.Add(aktivitet
End Functio
Public Sub Remove(ByVal aktivitet As Aktivitet
list.Remove(aktivitet
End Su
Public Sub Sort(
innerlist.Sort(_comparer
End Su
End Clas
Public Class aktivitetListSorte
Implements ICompare
Private _sortByField As Strin
Private _SortDirection As ListSortDirectio
Public Property SortByField() As Strin
Ge
Return _sortByFiel
End Ge
Set(ByVal Value As String
If Value = "" The
_sortByField = "aktivitetID
Els
_sortByField = Valu
End I
End Se
End Propert
Public Property SortDirection() As ListSortDirectio
Ge
Return _SortDirectio
End Ge
Set(ByVal Value As System.ComponentModel.ListSortDirection
_SortDirection = Valu
End Se
End Propert
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compar
Dim aX As Aktivitet = DirectCast(x, Aktivitet
Dim aY As Aktivitet = DirectCast(y, Aktivitet
Dim result As Int3
Select Case _sortByField.ToLowe
Case "aktivitetid
result = aX.AktivitetID.CompareTo(aY.AktivitetID
Case "isfaglig
result = aX.IsFaglig.CompareTo(aY.IsFaglig
Case "issocial
result = aX.IsSocial.CompareTo(aY.IsSocial
Case "aktivitetssted
result = aX.AktivitetsSted.CompareTo(aY.AktivitetsSted
Case "startdato
result = aX.StartDato.CompareTo(aY.StartDato
Case "starttid
result = aX.StartTid.CompareTo(aY.StartTid
Case "slutdato
result = aX.SlutDato.CompareTo(aY.SlutDato
Case "sluttid
result = aX.SlutTid.CompareTo(aY.SlutTid
Case "beskrivelse
result = aX.Beskrivelse.CompareTo(aY.Beskrivelse
Case "arrangoer
result = aX.Arrangoer.CompareTo(aY.Arrangoer
Case "kontakt
result = aX.Kontakt.CompareTo(aY.Kontakt
Case "ispublished
result = aX.IsPublished.CompareTo(aY.IsPublished
Case "maalgrupperegion
result = aX.MaalGruppeRegion.CompareTo(aY.MaalGruppeRegion
Case "maalgruppekontor
result = aX.MaalGruppeKontor.CompareTo(aY.MaalGruppeKontor
Case "maalgruppeafdeling
result = aX.MaalGruppeAfdeling.CompareTo(aY.MaalGruppeAfdeling
Case "titel
result = aX.Titel.CompareTo(aY.Titel
Case "postedby
result = aX.PostedBy.CompareTo(aY.PostedBy
Case "datecreated
result = aX.DateCreated.CompareTo(aY.DateCreated
Case "modifiedby
result = aX.ModifiedBy.CompareTo(aY.ModifiedBy
Case "datemodified
result = aX.DateModified.CompareTo(aY.DateModified
Case "email
result = aX.Email.CompareTo(aY.Email
Case "isonlinesignonavailable
result = aX.IsOnlineSignOnAvailable.CompareTo(aY.IsOnlineSignOnAvailable)
Case Else
result = aX.StartDato.CompareTo(aY.StartDato)
End Select
If SortDirection = ComponentModel.ListSortDirection.Descending Then
Return -result
Else
Return result
End If
End Function
Public Sub New()
MyClass.New("StartDato", ListSortDirection.Ascending)
End Sub
Public Sub New(ByVal aSortByField As String)
MyClass.New(aSortByField, ListSortDirection.Ascending)
End Sub
Public Sub New(ByVal aSortByField As String, ByVal aSortDirection As ListSortDirection)
_sortByField = aSortByField
_SortDirection = aSortDirection
End Sub
End Class
The field to sort by is set to: isfaglig
The items supposed to be sorted contains these values in the isfaglig field:
False
False
False
False
True
False
False
True
Now by I've come to the point where I've pinpointed the problem to this:
Public Sub Sort()
innerlist.Sort(_comparer)
End Sub
That works correct for any other field I've given it, but when sorting the boolean fields the "sorted" list is returned as:
True
True
True
True
False
True
True
False
Can anybody help me figure out why this sorting does not function as it is supposed to ??
Kind regards
Henning Kristensen
Been at this problem for 6 hours now, aka. time to admit my defeat and ask for help ;-
The code thats acting up looks like this
Imports System.ComponentMode
Public Class aktivitetList
Inherits System.Collections.CollectionBas
Private _comparer As New aktivitetListSorte
Default Public ReadOnly Property Item(ByVal idx As Int32) As Aktivite
Ge
If list.Count <= idx OrElse idx < 0 The
Throw New ArgumentException("Index was out of bounds"
End I
Return DirectCast(list.Item(idx), Aktivitet
End Ge
End Propert
Public ReadOnly Property ListSorter() As aktivitetListSorte
Ge
Return _compare
End Ge
End Propert
Public Function Add(ByVal aktivitet As Aktivitet) As Int3
Return list.Add(aktivitet
End Functio
Public Sub Remove(ByVal aktivitet As Aktivitet
list.Remove(aktivitet
End Su
Public Sub Sort(
innerlist.Sort(_comparer
End Su
End Clas
Public Class aktivitetListSorte
Implements ICompare
Private _sortByField As Strin
Private _SortDirection As ListSortDirectio
Public Property SortByField() As Strin
Ge
Return _sortByFiel
End Ge
Set(ByVal Value As String
If Value = "" The
_sortByField = "aktivitetID
Els
_sortByField = Valu
End I
End Se
End Propert
Public Property SortDirection() As ListSortDirectio
Ge
Return _SortDirectio
End Ge
Set(ByVal Value As System.ComponentModel.ListSortDirection
_SortDirection = Valu
End Se
End Propert
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compar
Dim aX As Aktivitet = DirectCast(x, Aktivitet
Dim aY As Aktivitet = DirectCast(y, Aktivitet
Dim result As Int3
Select Case _sortByField.ToLowe
Case "aktivitetid
result = aX.AktivitetID.CompareTo(aY.AktivitetID
Case "isfaglig
result = aX.IsFaglig.CompareTo(aY.IsFaglig
Case "issocial
result = aX.IsSocial.CompareTo(aY.IsSocial
Case "aktivitetssted
result = aX.AktivitetsSted.CompareTo(aY.AktivitetsSted
Case "startdato
result = aX.StartDato.CompareTo(aY.StartDato
Case "starttid
result = aX.StartTid.CompareTo(aY.StartTid
Case "slutdato
result = aX.SlutDato.CompareTo(aY.SlutDato
Case "sluttid
result = aX.SlutTid.CompareTo(aY.SlutTid
Case "beskrivelse
result = aX.Beskrivelse.CompareTo(aY.Beskrivelse
Case "arrangoer
result = aX.Arrangoer.CompareTo(aY.Arrangoer
Case "kontakt
result = aX.Kontakt.CompareTo(aY.Kontakt
Case "ispublished
result = aX.IsPublished.CompareTo(aY.IsPublished
Case "maalgrupperegion
result = aX.MaalGruppeRegion.CompareTo(aY.MaalGruppeRegion
Case "maalgruppekontor
result = aX.MaalGruppeKontor.CompareTo(aY.MaalGruppeKontor
Case "maalgruppeafdeling
result = aX.MaalGruppeAfdeling.CompareTo(aY.MaalGruppeAfdeling
Case "titel
result = aX.Titel.CompareTo(aY.Titel
Case "postedby
result = aX.PostedBy.CompareTo(aY.PostedBy
Case "datecreated
result = aX.DateCreated.CompareTo(aY.DateCreated
Case "modifiedby
result = aX.ModifiedBy.CompareTo(aY.ModifiedBy
Case "datemodified
result = aX.DateModified.CompareTo(aY.DateModified
Case "email
result = aX.Email.CompareTo(aY.Email
Case "isonlinesignonavailable
result = aX.IsOnlineSignOnAvailable.CompareTo(aY.IsOnlineSignOnAvailable)
Case Else
result = aX.StartDato.CompareTo(aY.StartDato)
End Select
If SortDirection = ComponentModel.ListSortDirection.Descending Then
Return -result
Else
Return result
End If
End Function
Public Sub New()
MyClass.New("StartDato", ListSortDirection.Ascending)
End Sub
Public Sub New(ByVal aSortByField As String)
MyClass.New(aSortByField, ListSortDirection.Ascending)
End Sub
Public Sub New(ByVal aSortByField As String, ByVal aSortDirection As ListSortDirection)
_sortByField = aSortByField
_SortDirection = aSortDirection
End Sub
End Class
The field to sort by is set to: isfaglig
The items supposed to be sorted contains these values in the isfaglig field:
False
False
False
False
True
False
False
True
Now by I've come to the point where I've pinpointed the problem to this:
Public Sub Sort()
innerlist.Sort(_comparer)
End Sub
That works correct for any other field I've given it, but when sorting the boolean fields the "sorted" list is returned as:
True
True
True
True
False
True
True
False
Can anybody help me figure out why this sorting does not function as it is supposed to ??
Kind regards
Henning Kristensen