How do I Sort a List?

How do I Sort a List?

Old forum URL: forums.lhotka.net/forums/t/7253.aspx


superkuton posted on Thursday, July 09, 2009

My DB objects:

Parent:  Student (StudentID, etc.)
Child:  Assessment(AssessmentID, StudentID, etc.)

Our users need to edit the child collection which should be sorted according to a certain criteria: LastName of the Students.

Should I create the collection as an editable root? Or as an editable child collection of a "read-only" parent?

How should I implement the sort in the Child Collection Object?

RockfordLhotka replied on Thursday, July 09, 2009

If you are using Windows Forms, consider using SortedBindingList to wrap your actual list. Then bind the UI to the SortedBindingList, and sorting should be automatic (using a datagrid, etc).

If you are using other technologies (WPF, etc) you may find that LINQ queries are a more powerful solution. Sadly WPF doesn't fully support IBindingList collections (like SortedBindingList), and so the automatic ability to sort collections won't work without you doing some manual work.

superkuton replied on Friday, July 10, 2009

Yap I'm using windows forms, and the sorting is now automatic. Thanks for the SortedBindingList.

And thanks for CSLA, Rocky.


Copyright (c) Marimer LLC