0

I have a collection of items that I am displaying in a DataGrid in WPF.

These items have the property Status, which can either be Approved, Pending, Draft or Archived.

I have set up an ICollectionView as follows:

formView = CollectionViewSource.GetDefaultView(Forms);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Status");
formView.GroupDescriptions.Add(groupDescription);

I then bind this view to the DataGrid and it correctly groups and display my items.

My issue, is I need Archived to be at the bottom of the list, and collapsed by default however my binding automatically puts it before the other status. How can I achieve this?

Thanks.

Loocid
  • 6,112
  • 1
  • 24
  • 42

1 Answers1

1

You could either sort the source collection:

var formView = CollectionViewSource.GetDefaultView(Forms.OrderBy(x =>
{
    switch (x.Status)
    {
        case "Archived":
            return 1;
        default:
            return 0;
    }
}));

Or the CollectionView:

CollectionViewSource with custom sort

mm8
  • 163,881
  • 10
  • 57
  • 88