I want to get an bunch of items from a list box, add them to an array, sort it, then put it back into a different listbox. Here is what I have came up with:
ArrayList q = new ArrayList();
foreach (object o in listBox4.Items)
q.Add(o);
q.Sort();
listBox5.Items.Add(q.ToString());
But it doesnt work. Any ideas?
Try AddRange
Sort Listbox Desc
You could just use the ListBox.Sorted built in functionality
Setting ListBox5.Sorted=true will ensure that the items in the listbox are sorted and any subsequent items added to the listbox will be added in the correct order.
Of course this assumes that you have simple sort requirements as suggested by your example.
If you are using .Net3.5 use linq to finish this task.Here i used list to convert and sorted