Codie Vincent Codie Vincent - 1 year ago 132
C# Question

Sorting a list of items in a list box

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?

HCL HCL
Answer Source
ArrayList q = new ArrayList(); 
foreach (object o in listBox4.Items) 
        q.Add(o);
} 
q.Sort(); 
listBox5.Items.Clear();
foreach(object o in q){
    listBox5.Items.Add(o); 
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download