Hi!
I'm populating a grid with data from a oracle database, like this :
"select name, to_char(date,'DD-MON-YYYY HH24:MI:SS') from atable".
So when using the sort functionality in the grid, the values are sorted by their string value not their actual date value. But i don't like this, and i would like to still have the date formated but when sorted to be sorted as a datetime column. How do you recomment i should do this ?
Thank you!
My bad!
The comparer was working, i was just checking in the wrong place!
Thank you a lot for your help!
Problems are piece of cake you're working with the great infragistics support team! :)
Thanks Mike and Hristo!
I've tried the SortComparer solution, and wrote this comparer :
public class DateTimeComparer : IComparer { internal DateTimeComparer() { } int IComparer.Compare(object x, object y) { try { UltraGridCell xCell = (UltraGridCell)x; UltraGridCell yCell = (UltraGridCell)y; DateTime dtx = DateTime.Parse(xCell.Value.ToString()); DateTime dty = DateTime.Parse(yCell.Value.ToString()); return DateTime.Compare(dtx, dty); } catch (Exception ex) { return 0; } } }
public class DateTimeComparer : IComparer {
internal DateTimeComparer() {
}
int IComparer.Compare(object x, object y) {
try {
UltraGridCell xCell = (UltraGridCell)x;
UltraGridCell yCell = (UltraGridCell)y;
DateTime dtx = DateTime.Parse(xCell.Value.ToString());
DateTime dty = DateTime.Parse(yCell.Value.ToString());
return DateTime.Compare(dtx, dty);
catch (Exception ex) {
return 0;
But unfortunately, it doesn't seem to apply. I still get an ordering based on the string values.
Am i doing something wrong in the code?
The best thing to do is.. don't use strings for dates. Doing so will cause problems in a number of areas like sorting, filtering, and calculations.You would be better off getting the dates as DateTime structures and then applying formatting in the UI. The grid column has a Format property which you could use to display the dates in the format you want without converting them to strings.
But, if for some reason, you cannot do that, then the alternative would be to write a SortComparer for the column that converts the strings into dates and compares them.
Hello,
To achieve your goal your column should be of type DateTime, then set a format string for this column with:
UltraGrid. DisplayLayout.Bands[0].Columns["Column key"].Format = " dd-MMM-yyyy HH:mm:ss";
Please let me know if you have any further questions.