3

I can't find how to add custom sorting to WPF ListView control? I don't need to sort by columns asc or desc, I need a custom one with some algorithm in it?

can you help me?

Thank you!

1
  • 1
    use ObservableCollection as ItemsSource and sort your collection in whatever logic you want... it will reflect on UI Commented May 21, 2014 at 11:07

1 Answer 1

5

You can use CustomSort property on ListCollectionView provided that you implement IComparer for your class:

//somewhere in code behind of your window:
var view = (ListCollectionView)CollectionViewSource.GetDefaultView(Items); //Items is an ObservableCollection<T> 
view.CustomSort = new MyComparer(); //MyComparable implements IComparer

Any control bound to your Items such as ListBox will display elements in order.

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

1 Comment

There was a problem with this method as I remember.. But now it seems like ok. Thank you!

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.