I am having a Infragistics XamComboEditor which needs its values to be sorted according to Excel's ascending sorting logic. It is bound to an ObservableDictionary<int, string> with DisplayMemberPath as Value. This value can have special characters, numbers and alphabets together or simply either one of them. Is there any way to achieve this requirement without handling all the cases manually?

I have tried using ChatGPT but the code provided by it is not providing expected results. This is a sample input in excel Sorting it in ascending order in Excel givs following result

1

There are 1 best solutions below

0
On

Define a property in your code(View model probably) of type ICollectionView:

ICollectionView Source { get; set; }

Create a default Collection View somewhere in your code and it actually maintains a stack of SortDescription objects, each of them being a Structure which can hold information of a Column and the Direction of Sorting - https://learn.microsoft.com/en-us/dotnet/desktop/wpf/data/how-to-get-the-default-view-of-a-data-collection?view=netframeworkdesktop-4.8

Item source of your control should be set like this:

YourControl.ItemsSource = CollectionViewSource.GetDefaultView(this.Source);

Finally, you can easily apply sorting like this:

Source.SortDescriptions.Add(new SortDescription("Name",SortDirection.Descending));

by „Name” in desc order.