Is there any easy way to sort listbox items by DateTime values?
In my listbox1 I have items formatted like this: "2013.01.08 19:29:52" so it's just someDateTimeValue.ToString()
I also marked it as duplicate, but with closer look, it is slightly different as it involves DateTime
– Tilak
If your DateTime format is yyyy.MM.dd hh:mm:tt then default sorting(Array.Sort) will work. Otherwise you need to first parse it as DateTime, then do the sorting.
– Tilak
3 Answers
1
votes
if you have 2 ListBoxes you could do something like the following
ArrayList arList = new ArrayList();
foreach (object obj in listBox1.Items)
{
arList.Add(obj);
}
arList.Sort();
listBox2.Items.Clear();
foreach(object obj in arList)
{
listBox2.Items.Add(obj);
}
try to sort a list of dates and after that put in the listbox.
dateList.Sort();
var items = new SelectList(dateList);
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
DateTime
– TilakDateTime
format is yyyy.MM.dd hh:mm:tt then default sorting(Array.Sort) will work. Otherwise you need to first parse it as DateTime, then do the sorting. – Tilak