Keeping a list sorted

Thread is closed for posting
2 posts, 0 answers
  1. cayates
    cayates avatar
    71 posts
    Member since:
    Feb 2007

    Posted 02 Feb 2009 Link to this post


    I have a list of objects that are mapped to a table using Open Access.  Each time a new object is added to the list it needs to be sorted using a custom comparison method.  Normally I would just create an IComparer class and use List<>.Sort(IComparer<>), however, when I try to do this with the Open Access enhanced list I get this error:

    Unable to cast object of type 'Telerik.OpenAccess.TrackedList`1[CJIS.Model.Charge]' to type 'System.Collections.Generic.List`1[CJIS.Model.Charge]'.

    The TrackedList object does not have a Sort method.  So how would I accomplish this?

    Thank you.
  2. Jan Blessenohl
    Jan Blessenohl avatar
    707 posts

    Posted 04 Feb 2009 Link to this post

    Hello cayates,
    The speciality about sorting is it will remove/add persistent objects from/to the collection, those operations are possibly not intended and we do not implement the sort interface.

    What you can do is to implement your derivation from TrackedList<T> and add the sort capability. You can use such a SortableTrackedList<T>:TarckeList<T> directly in your persistent model.

    Sincerely yours,
    Jan Blessenohl
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top