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
2. First clicking
3. Second clicking
Continue reading...
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
2. First clicking
3. Second clicking
Continue reading...