Sorting Dates
Hi Guys,
I have a P-C relation GGC and I have a few columns that have a string datatype. However the data in the columns are Dates and I need to sort them as such instead of a alphanumeric sort.
Is there a way in the TableControlQueryAllowSortColumn event to handle this kind of sorting.
Regards,
Chris Wescott
SIGN IN To post a reply.
4 Replies
AD
Administrator
Syncfusion Team
May 17, 2006 05:04 AM UTC
Hi Chris,
This can be achieved by having a custom comparer and specifying it to the particular SortedColumn in the TableControlQueryAllowSortColumn event handler. This was shown in the attached sample.
Regards,
Calvin.
DateSort.zip
DateSort.zip
CW
Chris Wescott
May 18, 2006 10:19 PM UTC
Hi Calvin,
I am trying to implement this soultion but the
return xd.compareto(YD) seems to alwyas be return -1. This just doesn''t seem right.
XD = 3/26/1990
YD = 11/13/1998
It then turns my grid completely white like all the rows have been filtered out.
PS,
The sample you sent has all the same dates in it.
Regards,
Chris Wescott
AD
Administrator
Syncfusion Team
May 19, 2006 03:45 AM UTC
Hi Chris,
Sorry for the inconvenience. The sample works fine for me, and I am not able to see the mentioned issue here. I have attached the sample with different dates. Can you able to see the issue in the attached sample? Or can you please tell me how to reproduce the issue in the attached sample so that we can get back soon with a solution at the earliest.
Regards,
Calvin.
DateSort0.zip
DateSort0.zip
CW
Chris Wescott
May 19, 2006 02:33 PM UTC
Hi Calvin,
I found the solution. This type of IComparer routine throws the catch is the date is a null. so I implemented this. Just incase someone in the future might want to do the same thing.
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
If x Is Nothing AndAlso y Is Nothing Then
Return 0
ElseIf x Is Nothing Or IsDBNull(x) Then
If IsDBNull(x) Then
x = "01/01/1800"
Else
Return -1
End If
ElseIf y Is Nothing Or IsDBNull(y) Then
If IsDBNull(y) Then
y = "01/01/1800"
Else
Return 1
End If
Else
Try
Dim xd As DateTime = Convert.ToDateTime(x)
Dim yd As DateTime = Convert.ToDateTime(y)
Dim ret As Integer = xd.CompareTo(yd)
''System.Diagnostics.Debug.WriteLine(String.Format("Return Val:{0}, xd:{1}, yd:{2}", ret, xd, yd))
Return ret
Catch
Throw New ArgumentException("Value is not in a proper date format")
End Try
End If
End Function
Mainly the change was if it was null then make the date 01/01/1800. Just wanted to pass the knowledge on.
Regards,
Chris Wescott
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
-
CW Chris Wescott
- May 16, 2006 02:44 PM UTC
- May 19, 2006 02:33 PM UTC