Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Manipulating Data Prior To Display
Message
From
07/12/2004 12:17:24
 
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00967471
Message ID:
00967520
Views:
14
Kevin,

The ArrayList.Sort() method handles it all for you, if you just give it a parameter that implements the IComparer interface, so don't worry about object x and object y ... the Sort takes care of all that.

Where you define this class is up to you ... we have a separate namespace and classes for our "base classes". For now, I'd just put it wherever you feel comfortable (same file is fine) until you get it working.

~~Bonnie


>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
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform