Force a group in ListCollectionView to be first

c#, wpf

Solution

Try to use an auxiliary property:

public class Item
{
    public ProfileTypeEnum ProfileType { get; set; }
    public string ProfileName { get; set; }
    public int ProfileTypeValue { get { return (int)ProfileType; } }
}

give values to the enumeration:

public enum ProfileTypeEnum
{
    CurrentSettings=0,
    CustomSettings=1,
    DefaultSettings=2
}

and add a sort description:

Profiles.SortDescriptions.Add(new SortDescription("ProfileTypeValue", ListSortDirection.Ascending));
Profiles.SortDescriptions.Add(new SortDescription("ProfileName", ListSortDirection.Ascending));

this way you can use enumeration's values to alter the order and force one on top.

Problem

I am using a ListCollectionView as a datacontext to a tab control. I have added a GroupDescription to it based on an enum and I want a particular group to appear as the first tab in the tab control however now it is always being put on the bottom. ``` Profiles = new ListCollectionView(_profiles); Profiles.GroupDescriptions.Add(new PropertyGroupDescription("ProfileType")); Profiles.SortDescriptions.Add(new SortDescription("ProfileName", ListSortDirection.Ascending)); ``` _profiles is an ObservableCollection of my profile ViewModels. My Enum looks like: ``` public enum ProfileTypeEnum { CurrentSettings, CustomSettings, DefaultSettings } ``` So how can I force the CurrentSettings group to always be first?

Original source