We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sorting Dates

Thread ID:

Created:

Updated:

Platform:

Replies:

44188 May 16,2006 02:44 PM UTC May 19,2006 02:33 PM UTC Windows Forms 4
loading
Tags: GridControl
Chris Wescott
Asked On May 16, 2006 02:44 PM UTC

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

Administrator [Syncfusion]
Replied On 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

Chris Wescott
Replied On 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

Administrator [Syncfusion]
Replied On 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

Chris Wescott
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;