Sorting listbox in wpf

ListCollectionView can be used to sort listbox in wpf.

Create ListCollectionView instance providing the list collection.

var view = new ListCollectionView((IList)data);

listbox.DataContext = view;

In the button click event you can add instance of SortDescription to which column and direction you wish to sort the view. Since listbox is bound to the ListCollectionView , sorting ListCollectionView also sorts the listbox.

view.SortDescriptions.Add(new SortDescription() { PropertyName = columnName, Direction =  ListSortDirection.Ascending });
, , , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share to Facebook Share to Twitter Stumble It Share on Tumblr Digg More...