Reputation: 6440
I have in a form two combo boxes that have the exact itemssource property. Both combo boxes need to be sorted, but in two different ways. One is sorted by the ID (numeric), the other one by Name(Alphabetic).
Is it possible to do such a thing?
Thanks
Upvotes: 1
Views: 232
Reputation: 180788
How to sort listbox and comboboxes in WPF http://www.kudzuworld.com/Blogs/Tech/20070815A.en.aspx
Since WPF does not provide a "Sort Order" property for its combo boxes, you need two different collections.
In the link I provided above, a commenter posted the following method using a ListCollectionView object to get a custom sort. This allows a single collection from your data source to be used, while adding an additional layer of collections for sorting:
// Using System.ComponentModel;
ListCollectionView view = new ListCollectionView (channel.Members);
view.SortDescriptions.Add(new SortDescription("lastName", ListSortDirection.Ascending);
view.SortDescriptions.Add(new SortDescription("firstName", ListSortDirection.Ascending);
view.CustomSort = new IComparerImplementation; //Do this if you want a custom sort;
view.Refresh();
Upvotes: 0
Reputation: 5488
CollectionView is made just for that: http://bea.stollnitz.com/blog/?p=38
Upvotes: 2