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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridGroupingControl and custom dates

Thread ID:





71312 Jan 25,2008 06:02 PM UTC Jan 29,2008 08:37 PM UTC WinForms 3
Tags: GridControl
Jay Delp
Asked On January 25, 2008 06:02 PM UTC

I have a GridGroupControl populated with data from a DataTable. One of the table columns is a CustomDate instance. (It knows how to format itself based on user settings in our application. It also implements IComparable so it can be sorted.)

The column is added to the data table as:
myDataTable.Columns.Add("ProcessDate", typeof(CustomDate));

When the date appears in the grid column is is formatted correctly, i.e. "01/25/2008".

If I click on the column heading to sort, the sort seems to be based on the string value in the grid as opposed to the date value of the custom date, therefore the dates don't always appear in the expected order after a sort.

Is there a way to solve this problem?

haneefm [Syncfusion]
Replied On January 28, 2008 11:26 PM UTC

Hi Jay,

You need to implement custom sorting to do this. You can add a custom IComparer to the SortColumnDescriptor for this particular column. This can be done by setting the Comparer property on the SortColumnDescriptor. In the custom IComparer object, you can sort based on any criteria you want.

this.gridGroupingControl1.TableDescriptor.SortedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(SortedColumns_Changing);

void SortedColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
if (e.Action == Syncfusion.Collections.ListPropertyChangedType.Add)
SortColumnDescriptor scd = e.Item as SortColumnDescriptor;
if (scd.Name == "Version" && scd.Comparer == null)
scd.Comparer = new CustomComparer();

Please refer the below sample that implements this custom sorting for your needs.

Best regards,

Replied On January 29, 2008 08:53 AM UTC

Thx, that was also what i needed. Use this code for dates

public class CustomComparerDates : IComparer
public int Compare(object x, object y)

DateTime d1 = DateTime.Parse(x.ToString());
DateTime d2 = DateTime.Parse(y.ToString());
if (d1 == null || d1 == DateTime.MinValue)
return -1;
else if (d2 == null || d2 == DateTime.MinValue)
return 1;
return d1.CompareTo(d2);


Jay Delp
Replied On January 29, 2008 08:37 PM UTC

Okay, plugged in the event handler from Haneef and a variation of the Comparer from Gert and all is working as desired.



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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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