Keith,
You shouldn't have to add another field to your collection. Just compare
based on the Make property. You would be adding 1 extra method to your
CarPref class instead of 2 extra methods to your collection. Just my $0.02.
-- Nick
-----Original Message-----
From: padnug@xxxxxxxxxxxxxxx [mailto:padnug@xxxxxxxxxxxxxxx] On Behalf Of
Keith R. Pinster
Sent: Tuesday, August 23, 2005 2:39 PM
To: padnug@xxxxxxxxxxxxxxx
Subject: [padnug] Re: SOLUTION: Moving object order in a collection in C#
This looks good and I'm going to have to remember it, but I think
I'll stick with swapping the items for now and see how that works.
Mainly because I'd rather not have an extra field in the collection
just for the purpose of sorting.
This would be great, however, if I have a collection that I want to
sort on different "fields" for particular reasons without having to
re-order the entries each time.
For this, it's a matter of having the items in a particular order for
loading into the app. They will never be "sorted" for any temporary
reason.
Thank!
--- In padnug@xxxxxxxxxxxxxxx, "berkalex" <berkalex@xxxx> wrote:
> Keith,
>
> You should be able to have the CarPref class implement IComparable,
then
> just call List.Sort(). IIRC, implementing IComparable consists of
writing
> only 1 method (Compare() or CompareTo(), something like that).
>
> -- Nick
>
>
> -----Original Message-----
> From: padnug@xxxxxxxxxxxxxxx [mailto:padnug@xxxxxxxxxxxxxxx] On
Behalf Of
> Keith R. Pinster
> Sent: Tuesday, August 23, 2005 12:55 PM
> To: padnug@xxxxxxxxxxxxxxx
> Subject: [padnug] SOLUTION: Moving object order in a collection in
C#
>
>
> Here's how I decided to do it:
>
> Instead of using an Order field, I use the following code in the
> MoveUp and MoveDown methods:
>
> public void MoveDown(CarPref carPref)
> {
> CarPref carCopy = new CarPref(carPref.Model, carPref.Make);
> List.Insert(List.IndexOf(carPref)+2, carCopy );
> List.Remove(carPref);
> }
> public void MoveUp(CarPref carPref)
> {
> CarPref carCopy = new CarPref(carPref.Model, carPref.Make);
> List.Insert(List.IndexOf(carPref)-1, carCopy );
> List.Remove(carPref);
> }
>
> I haven't tested it yet, but it looks like it'll work. I'll report
> back once I have it running, just in case anyone else is interested.
>
> --- In padnug@xxxxxxxxxxxxxxx, "Keith R. Pinster" <dimondwoof@xxxx>
> wrote:
> > I've got an object that has a set of sub-objects. I want to be
> able to
> > retrieve the sub-objects in a certain order. Is there a way to
> change
> > the index of the sub-objects?
> >
> > E.G:
> > Favorites:
> > Cars:
> > 1. Corvette
> > 2. Nova
> > 3. Firebird
> >
> > User wants to change the order so that it reads:
> > 1. Corvette
> > 2. Firebird
> > 3. Nova
> >
> > Currently I'm tracking the order with an Order int field, but this
> > seems really messy and error prone. Any ideas?
>
>
>
>
>
>
> Yahoo! Groups Links
SPONSORED LINKS
Portland
<http://groups.yahoo.com/gads?t=ms&k=Portland+oregon&w1=Portland+oregon&w2=S
oftware+developer&w3=Computer+internet&c=3&s=68&.sig=S82HyuXoy8HI79OVDPQGig>
oregon Software
<http://groups.yahoo.com/gads?t=ms&k=Software+developer&w1=Portland+oregon&w
2=Software+developer&w3=Computer+internet&c=3&s=68&.sig=ZwMIT9wBOJJAZZHIc4Ui
Xg> developer Computer
<http://groups.yahoo.com/gads?t=ms&k=Computer+internet&w1=Portland+oregon&w2
=Software+developer&w3=Computer+internet&c=3&s=68&.sig=exfGXbNGjvyPqxL5qcXuA
w> internet
_____
YAHOO! GROUPS LINKS
* Visit your group "padnug <http://groups.yahoo.com/group/padnug> "
on the web.
* To unsubscribe from this group, send an email to:
padnug-unsubscribe@xxxxxxxxxxxxxxx
<mailto:padnug-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .
_____
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
<font face=arial size=-1><a
href="http://us.ard.yahoo.com/SIG=12hijelkr/M=362329.6886308.7839368.1510227/D=groups/S=1705007709:TM/Y=YAHOO/EXP=1124842866/A=2894321/R=0/SIG=11dvsfulr/*http://youthnoise.com/page.php?page_id=1992
">Fair play? Video games influencing politics. Click and talk back!</a>.</font>
--------------------------------------------------------------------~->
|