sort in memory - 2 fieldindexes

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 13-Jul-2007 16:52:24   

I have a Collection in memory. How do I sort it in memory desc based on 2 fieldindexes.

Right now I call,

this.Sort(MyFieldIndex.Field1, ListSortDirection.Descending);

I'd like to sort by MyFieldIndex.Field1 desc then by MyFieldIndex.Field2 desc

I couldn't find a way to pass a SortExpression object to the collection.

Thanks!

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 13-Jul-2007 17:56:40   

I think this is it???? (in a partial Collection class)

                EntityView<OfferLayerEntity> view = this.DefaultView;
                SortExpression sort = new SortExpression(OfferLayerFields.XXX| SortOperator.Descending);
                sort.Add(OfferLayerFields.YYY| SortOperator.Descending);
                view.Sorter = sort;

Will this give me in view[0] the top XXX then top YYY ?

Ian

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jul-2007 05:47:32   

The result should be (assuming field1=char field2=char):


f1   f2
--------
Z     Z
Z     Y
Z     X
X     Z
X     Y
X     X
...
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 14-Jul-2007 13:22:44   

ianvink wrote:

I think this is it???? (in a partial Collection class)

                EntityView<OfferLayerEntity> view = this.DefaultView;
                SortExpression sort = new SortExpression(OfferLayerFields.XXX| SortOperator.Descending);
                sort.Add(OfferLayerFields.YYY| SortOperator.Descending);
                view.Sorter = sort;

Will this give me in view[0] the top XXX then top YYY ?

Ian

COrrect. Sorting on 2 fields or more should be done using a view. Which is the preferred in-memory sort methodology anyway simple_smile

Frans Bouma | Lead developer LLBLGen Pro