Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Manipulating Data Prior To Display
Message
De
07/12/2004 12:06:22
 
 
À
07/12/2004 10:52:44
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00967471
Message ID:
00967518
Vues:
12
Thanks very much for the reply, although I'm afraid that it raises some more questions...

>I've not sorted ArrayLists before, but I have sorted ListViews. The ArrayList.Sort() method needs a parameter that implements the IComparer interface. You'll basically have to implement a Sorter class yourself, but part of your problem with sorting your ArrayList, I think, is that the date is part of the text field (or at least that's what it sounds like from your description), so you'd have to do some string manipulation to get the last part of your text.

Yes, I think you have understood. An example would be:

Item 1 06-Nov-04
Item after one 03-Nov-04
Another Item 11-Nov-04

So what I want is to end up with the above sorted to row 3 then 1 then 2.

>To implement a date sorter class, you'd need to do something like this:
>
>public class MyArrayListSorter: IComparer
>{
>	#region Methods
>	public virtual int Compare(object x, object y)
>
Where do object x and object y come from? Also, does this code go in the same .cs file as I am currently working in (like a method or procedure in VFP) or does it go in a separate file?

>
>	{
>		string s1, s2;
>
>		s1 = x.ToString().Trim();
>		s2 = y.ToString().Trim();
>
>		s1 = s1.Substring(s1.Length() - 9);
>		s2 = s2.Substring(s2.Length() - 9);
>
>		if (s1.Trim().Length > 0)
>			d1 = DateTime.Parse(s1);
>		else
>			d1 = new DateTime(1900, 1, 1);
>
>		if (s2.Trim().Length > 0)
>			d2 = DateTime.Parse(s2);
>		else
>			d2 = new DateTime(1900, 1, 1);
>
>		if (d1 < d2) {return -1;}
>		else if (d1 > d2) {return 1;}
>		else {return 0;}
>	}
>
I can see this comparing two dates, but how does it compare a date with all of the other dates?

Kevin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform