The IComparer for date sorting

  • Thread starter Thread starter gaxjyxq
  • Start date Start date
G

gaxjyxq

Guest
The code below is for sorting date column, the first clicking is right, but the second clicking is not right, why?

Public Class Form1
Private Sub ColumnHeader1_Click(sender As Object, e As EventArgs) Handles ColumnHeader1.Click
Static oSorter As New AdvTreeSorter
ColumnHeader1.SortComparer = oSorter
ColumnHeader1.Sort()
End Sub
End Class

Public Class AdvTreeSorter

Implements Collections.IComparer
Protected m_oCulture As Globalization.CultureInfo = Globalization.CultureInfo.CurrentCulture

Private Function Compare(ByVal o1 As Object, ByVal o2 As Object) As Integer Implements Collections.IComparer.Compare
Dim node1 As Node = o1
Dim node2 As Node = o2
Dim sTxt1 As String = node1.Text
Dim sTxt2 As String = node2.Text

Dim dDate1 As Date = Date.Parse(sTxt1, m_oCulture.DateTimeFormat)
Dim dDate2 As Date = Date.Parse(sTxt2, m_oCulture.DateTimeFormat)

Return Date.Compare(dDate1, dDate2)
End Function
End Class

1. Init

1548731.png

2. First clicking

1548732.png

3. Second clicking

1548733.png

Continue reading...
 
Back
Top