Hi,
I have a bit of an odd problem. I have a grid that i must load some data to and sort it by date. I implemented CompareTo but it doesn't seem to work at all.
The objects in the grid seem to be put there at random. I tried to implement compareto in 3 ways. None of them worked. I do the sorting before i bind to the grid.
The code for the compareto method is this:
public int CompareTo(Issue to)</pre></pre> {
- if (this.LastStatusDate.Year > to.LastStatusDate.Year) return 1;
- else return 0;
- if ((this.LastStatusDate.Year == to.LastStatusDate.Year) &&
- (this.LastStatusDate.Month > to.LastStatusDate.Month)) return 1;
- else return 0;
- if ((this.LastStatusDate.Year == to.LastStatusDate.Year) &&
- (this.LastStatusDate.Month == to.LastStatusDate.Month) &&
- (this.LastStatusDate.Day > to.LastStatusDate.Day)) return 1;
- else return 0;
- if ((this.LastStatusDate.Year == to.LastStatusDate.Year) &&
- (this.LastStatusDate.Month == to.LastStatusDate.Month) &&
- (this.LastStatusDate.Day == to.LastStatusDate.Day) &&
- (this.LastStatusDate.Hour > to.LastStatusDate.Hour)) return 1;
- else return 0;
- }
The other 2 versions i tried were:
public int CompareTo(Issue to)
{
if (this.LastStatusDate.CompareTo(to.LastStatusDate)<0) return 1;
else return 0;
}
public int CompareTo(Issue to)
{
if (this.LastStatusDate > to.LastStatusDate) return 1;
else return 0;
}
I also tried DateTime.Compare(date1,date2). This didn't work either.
Any idea why the records in my gridview come up in complete disorder?
Thanks and regards,
Dani