Convert string date to date when using SortDescription

My WPF application uses XMLDataProvider for its data. XML file has

 <RELEASEDATE>dd/mm/yyyy</RELEASEDATE> 

for each of the listed items. I sort the data in the application using

 Listbox1.Items.SortDescriptions.Add(new SortDescription("RELEASEDATE", ListSortDirection.Descending)); 

Results are not expected because the date is treated as a string.

What is the most elegant way? Can I somehow convert the date to a string?

+4
source share
1 answer

You need to implement your own IComparer:

 class DateTimeComparer : IComparer { public int Compare(object x, object y) { //To Do : Implement DataTime Comparering } } 

and now assign an IComparer implementation of the ListCollectionView.CustomSort collection:

  ListCollectionView view = new ListCollectionView(ListBox.Items); view.CustomSort = new DateTimeComparer(); 

See a similar question

+2
source

All Articles