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

  • SEARCH
  • Home
  • 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 916705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:05:34+00:00 2026-05-15T18:05:34+00:00

I have a silverlight datagrid which is bound to a PagedCollectionView displaying a collection

  • 0

I have a silverlight datagrid which is bound to a PagedCollectionView displaying a collection of RowViewModels.

Each RowVM has a collection of CellViewModels, and the datagrid columns are templatecolumns and are generated dynamically with their content bound to Cell[0].Content, Cell[1].Content, etc. This is because the rowviewmodels are returned from a service, and can contain any number of columns and different types of content.

This works just fine, but I’ve run into problems when enabling sorting of columns in the datagrid. It seems the SortMemberPath property on DataGridColumns (which in the end becomes a SortDescription.PropertyName) won’t work with an expression containing an index, like “Cells[1].Content”.

Does anyone know a way around this?

  • 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-15T18:05:35+00:00Added an answer on May 15, 2026 at 6:05 pm

    Answering my own question here.

    I solved this by setting SortMemberPath on my generated columns to their index number in the RowVM.Cells collection, and added a SortOnMe property to my RowVMs.

    When the user sorts the datagrid, it will add a SortDescription containing the index number (taken from the SortMemberPath) to the PagedCollectionView. I monitor this by listening to the propertychanged event on the PagedCollectionView with the method below. It adds a new SortDescription telling the PagedCollectionView to sort on “SortOnMe”, and copies the data to sort on from the cell in question to row.SortOnMe.

    private bool _currentlySorting;
    private void PagedCollectionView_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        var pcv = (PagedCollectionView)sender;
        int columnIndex = 0;
        if (!_currentlySorting && e.PropertyName == "SortDescriptions" && pcv.SortDescriptions.Count == 1 && int.TryParse(pcv.SortDescriptions[0].PropertyName, out columnIndex)) {
            _currentlySorting = true; 
            pcv.SortDescriptions.Add(new SortDescription("SortOnMe", pcv.SortDescriptions(0).Direction));
            foreach (RowViewModel row in pcv.SourceCollection) {
                row.SortOnMe = row.Cells(columnIndex).Content;
            }
            _currentlySorting = false;
        }
    }
    

    It’s a pretty ugly solution, to be honest. But it works, and I’ve spent too much time bashing my head against this wall now.

    Since PagedCollectionView is a sealed class (why?!), the only other way I could think of doing this would be to create my own PagedCollectionView and handle sorting there.

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

Sidebar

Related Questions

I have a Silverlight 4 DataGrid which has its ItemsSource bound to an ObservableCollection
I have a DataGrid which is bound to a PagedCollectionView and the underlying collection
I have some 6 columns in Silverlight 4 Datagrid. On each cell in the
I have found that datagrid columns can be dynamically created and bound in Silverlight.
I have 2 silverlight controls on a form; datagrid which is bound to list
I have a Silverlight DataGrid of which I need to check if it has
In Silverlight 4 I have a DataGrid which is bound to a RIA DomainDataSource,
I have a silverlight datagrid control bound to a Dictionary<string, string> with autogenerate columns
I'm writing Silverlight application and I have a datagrid in which first two columns'
I have a Silverlight DataGrid that contains a single template column which displays a

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.