Reputation: 107
I have a ListBox
, it contains times. I have set the display format of the time string as shown in the screenshot.
How can I sort the times morning to evening, for example:
10:20:23 AM
11:56:65 AM
01:12:68 PM
Upvotes: 1
Views: 724
Reputation: 20121
You can do it like :
For sorting based on dates:
datesList.Sort((x, y) => x.StoredDate.CompareTo(y.StoredDate));
OR
For sorting on time of day:
var list = dateList.OrderBy(x => x.TimeOfDay).ToList();
Source: Sort DateTime List by Time & Sort List<DateTime> Descending
Upvotes: 1
Reputation: 6775
You must be using a List or any collection to bind the ListBox. Sort the List or collection by the column you are binding.
lstDates.OrderByAscending(x => x.Date)
Upvotes: 1