none
how to apply sort on collectionviewsource?

    Question

  • hi there,

    i 'm unble to find an example to apply sorting on collectionviewsource.

    can anyone gimme a sample application and if there are any video tutorials

    plz gimme the link also...

    thanx advance,

    Sris

     

    Saturday, May 06, 2006 5:34 PM

Answers

  • Hi Sris,

    The sample uses the SortDescriptions property not a Sort method (there's not Sort method on ListCollectionView). Have you tried something like the following as in the sample?

    ListCollectionview1.SortDescriptions.Add(new SortDescription("id", ListSortDirection.Ascending));

    If you're still having trouble you may want to share part of your code, we may be able to better assist you that way.

    HTH, Tina

    Friday, May 12, 2006 8:08 PM

All replies

  • hi ,

    thanx for the reply and the link

    I 'm having a problem with while i set the datacontext to the collectionview source .

    the problem is with the typecast. while declaring the collectionviewsource in the "StartHere" method it takes a collection object as an argument. But  i'm using a class with has a getter method for the mycollection.

    so it's is giving an exception over there that it cannot convert that class object to IEnumerable type.

    how could i solve this.........

    regards,

    Sris

     

    Tuesday, May 09, 2006 4:57 AM
  • Hi Sris,

    I may be misunderstanding your question but the GetDefaultView method takes an object that is a reference to the original data source object. In fact, the casting in the sample is unnecessary. We will update the sample to get rid of the IEnumerable casting:

    MyCollectionView = (ListCollectionView)CollectionViewSource.GetDefaultView(rootElem.DataContext);

    Since your original question was about CollectionViewSource, you may also want to take a look at the following sample, which shows how to sort data in markup using CollectionViewSource. http://windowssdk.msdn.microsoft.com/library/en-us/wpf_samples/html/dff152c8-d055-4d9b-86b0-e9e6e10ac181.asp?frame=true

    Thanks,
    Tina
    Wednesday, May 10, 2006 12:57 AM
  • hi tina,

    thanx for ur kind suggestion and sample

    i've tried to apply the way that was there in  the sample, but i couldnt get the Sort method on the ListCollectionView  (ListCollectionview1.Sort)

    where is the problem??

    ThanX,

    Sris

     

    Friday, May 12, 2006 4:32 AM
  • Hi Sris,

    The sample uses the SortDescriptions property not a Sort method (there's not Sort method on ListCollectionView). Have you tried something like the following as in the sample?

    ListCollectionview1.SortDescriptions.Add(new SortDescription("id", ListSortDirection.Ascending));

    If you're still having trouble you may want to share part of your code, we may be able to better assist you that way.

    HTH, Tina

    Friday, May 12, 2006 8:08 PM