0

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

2
  • 1
    You can provide SortDescriptions to CollectionView that can have more complex and custom sorting rules. This is my go to if I need filtering, sorting or grouping for display purposes. Commented Oct 21, 2023 at 17:39
  • 1
    I found this tutorial on using a CollectionView. Commented Oct 21, 2023 at 17:43

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.