Menu

Sorting a collection

homer111
2005-04-06
2013-03-07
  • homer111

    homer111 - 2005-04-06

    I have a order/lines collection. I need to sort the order.lines collection using the LineNumber property. I understand that CPersistentCollection doesn't support sorting and that i must subclass it  but, could you give me some orientation on how to make it?
    Googling about sorting i found a lot of information and code to sort any class, but the problem to use it was that this code only see CPersistentCollection and CPersistentObject classes but not my Order and Lines classes and of course, the property Lines doesn't exists on it.
    All this code works like: Sort(array,"Property",SortOrder)
    of course in order.lines the property LineNumber doesn't exists, i suppose this code expects a declaration of lines like Dim Lines() as Line.
    I think that my only solution was to sort the cpersistentcollection directly but i need some help!!! How can i access to Linenumber property of the Lines included in Order.Lines???

    TIA

     
    • Anonymous

      Anonymous - 2005-04-06

      Hi Homer111,

      The solution that worked for me was to create a wrapper around CPersistentCollection by calling Arraylist.Adapter() and creating a IComparer class for the particular class that I needed. Then I used the Sort() method with the IComparer class, and it worked.

      Dan

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.