Sort Collection After GetMulti

Posts   
 
    
billa1972
User
Posts: 9
Joined: 05-Feb-2004
# Posted on: 05-Feb-2004 20:36:24   

Hi,

How does one sort a collection after the call to Getmulti.

We get a collection from the database. Then we add a bunch of new entities to the collection, and we want to re-sort the collection. We tried adding a SortExpression and ApplySort but could not get it to work. We also did not find anything in the documentation about sorting after the GetMulti.

The Code:

Dim oSort As ISortExpression = New SortExpression(SortClauseFactory.Create(UDB.OfferStepFieldIndex.CampaignStepID, SortOperator.Ascending)) oOfferStepCollection.SortClauses = oSort oOfferStepCollection.ApplySort(oOfferStepCollection.SortProperty, ComponentModel.ListSortDirection.Ascending)

and also....

oOfferStepCollection.SortClauses.Add(oSort)

and also

oOfferStepCollection.SortClauses.Insert(0, oSort)

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 05-Feb-2004 21:00:21   

Sortclauses are used when fetching data.

You should call ApplySort() with the right property descriptor and direction specification. ApplySort is called by a grid for example when the user clicks on a column header. You have to set SupportsSorting to true prior binding the colleciton to the grid.

If you need help by creating the proper property descriptor let me know.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 05-Feb-2004 21:39:37   

I'd like to add, that the sorting is implemented through implementing IBindingList.

Here's code to construct a property descriptor you can use Dim prop As EntityPropertyDescriptor = New EntityPropertyDescriptor(EntityFieldFactory.Create(UDB.OfferStepFieldIndex.CampaignStepID), GetType(OfferStepEntity), False)

You then should pass prop to ApplySort.

(edit: whoops, VB.NET and C# constructs in 1 statement are not going to work stuck_out_tongue_winking_eye )

Frans Bouma | Lead developer LLBLGen Pro
billa1972
User
Posts: 9
Joined: 05-Feb-2004
# Posted on: 05-Feb-2004 22:50:36   

Hi,

I noticed in the OrmSupportClasses --> EntityCollectionBase, which implements IBindingList, there is no default sorting. SupportsSorting is readonly and AppySort throws an exception.

Am i supposed to override these?

Thanks

Bill

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 05-Feb-2004 23:01:31   

billa1972 wrote:

Hi,

I noticed in the OrmSupportClasses --> EntityCollectionBase, which implements IBindingList, there is no default sorting. SupportsSorting is readonly and AppySort throws an exception.

Am i supposed to override these?

SupportsSorting was read-only, however it was implemented in full (with ApplySort) in the update that was released with Adapter, thus in teh 1.0.2003.2 library. I'd suggest to install the latest installer from the website. simple_smile

(I assumed you were using that version)

Frans Bouma | Lead developer LLBLGen Pro
billa1972
User
Posts: 9
Joined: 05-Feb-2004
# Posted on: 06-Feb-2004 00:01:26   

Thanks,

Worked like a champ!

Bill