Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7519889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:58:33+00:00 2026-05-30T01:58:33+00:00

I am having a Observable Collection which contains my data values. I want to

  • 0

I am having a Observable Collection which contains my data values. I want to use Orderby in that collection but i am getting some exception like
"Cannot convert IEnumurable to ObservableCollection". Is there possible for using OrderBy or give me some options to Sort the Collection ?

Anyone please tell me the solution of this.
Thanks in advance.

My Code is:

get {

     return _availableStocks == null ? null : _availableStocks .OrderBy(z => z.Casepack.CasePackContents);   
     // Here _availableStocks is my collection
     //Here i am not able to use orderby in this collection Its showing error line
     // Here i need to sort the _availableStocks 
    }

My Actual code is:

   foreach (var cachedStock in AvailableSelectedStocks)
      {

          if (SelectedStock != null)
          {

            AvailableStocks= CollectionViewSource.GetDefaultView(_availableStocks);

            AvailableStocks.SortDescriptions.Add(new SortDescription(SelectedStock.Casepack.CasePackContents.Count.ToString(), ListSortDirection.Ascending));
            //In this above line i am getting the Sort descriptions only i am not getting the datas in the SourceCollection . how can i get values in this Collection

            this.SelectedStocks.Remove(SelectedStock);

            this.RaisePropertyChanged(Member.Of(() => AvailableStocks));

         }
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:58:34+00:00Added an answer on May 30, 2026 at 1:58 am

    The .OrderBy extension returns an IEnumerable, which is causing your problem. Attempting to sort in the getter is also somewhat bad.

    I would look into wrapping your observable collection with ICollectionView

    I.e

    public ICollectionView Stocks { get; private set; }
    
    private readonly ObservableCollection<Stock> stocks;
    

    Constructor

      stocks = new ObservableCollection<Stock>();
      Stocks = CollectionViewSource.GetDefaultView(stocks);
      Stocks.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
    

    Where ‘Name’ is the name of the Property of the class Stock that you wish to sort by.

    When you add to the observable collection ‘stocks’, the ‘Stocks’ ICollectionView will be updated and your view will display the items in the sorted order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tabcontrol which binds to an observable collection of tabs. The tabcontrol
What would be the best collection to use when binding a list of data
I am trying to populate a TreeView in silverlight, but I am having some
I'm working with a silverlight datagrid that is bound to an observable collection of
I have an observable collection that is exposed to the user by a collectionviewsource.
I want to use a hierarchical TreeView which I will populate programmatically. My XAML
I am having a problem in the xml serialization of observable collection. Here is
I'm having some trouble coming up with a xaml page that would bind to
Having a problem getting a TreeView control to display node images. The code below
I have a View that displays a DataGrid which is bound to an ObservableCollection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.