Microsoft Developer Network > Forenhomepage > Windows Presentation Foundation (WPF) > How can I sort a CollectionViewSource by a numeric string value.
Stellen Sie eine FrageStellen Sie eine Frage
 

BeantwortetHow can I sort a CollectionViewSource by a numeric string value.

  • Samstag, 4. Juli 2009 15:49Jeffrey Cumpsty TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    i have a collection view source which is populated with invoice items.

    Each invoice item contains an invoice reference which is stored in the database as a varchar, although it is a numeric value.

    I am using Linq to return my objects from the database and a converter to bind everything to the CVS.  I need to sort by the invoice reference but it is sorting as string

    (ie. 1, 100, 2, 200, 3, 300)

    How can I apply a converter to the the sort parameter before if performs the sort?

Antworten

  • Samstag, 4. Juli 2009 19:16Ted TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    Have a look at the CustomSort property, that is if your collectionview is a ListCollectionView:
    http://msdn.microsoft.com/en-us/library/system.windows.data.listcollectionview.customsort.aspx

Alle Antworten

  • Samstag, 4. Juli 2009 17:54Mariano O. Rodriguez TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    You'd better convert the invoice number in the LINQ query, you can solve this in the CollectionView sorting.
    http://weblogs.asp.net/marianor/
  • Samstag, 4. Juli 2009 18:14Jeffrey Cumpsty TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     
    You'd better convert the invoice number in the LINQ query, you can solve this in the CollectionView sorting.
    http://weblogs.asp.net/marianor/

    Please Clarify....Did you mean to type "CAN'T solve this in the Collectionview sorting"?



    As a workaround I have added an "InvoiceNumberInt" property to my Invoice.  Perhaps this is the best way to do it in the long run.  One of the things I like about the entity framework is that everything is a partial class so it makes is very easy to add methods and properties that I need.

    Cheers.
  • Samstag, 4. Juli 2009 18:22Mariano O. Rodriguez TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     

    SortDescription class only receives the name of the property and sort direction, there is not any way to add custom logic to apply a converter to order in a different way.


    http://weblogs.asp.net/marianor/
  • Samstag, 4. Juli 2009 19:16Ted TeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillenTeilnehmermedaillen
     Beantwortet
    Have a look at the CustomSort property, that is if your collectionview is a ListCollectionView:
    http://msdn.microsoft.com/en-us/library/system.windows.data.listcollectionview.customsort.aspx