Greetings everyone,
hope you all have a lovely weekend. so i have this new question which pins me down atm, Alright here i go : "C#" i have this listBox1, i want to transfer all the items to another ListBox, however They have to be Sorted Ascending. if anyone can point me in right direction that'll be most welcome!
As always, Thank you for reading this topic :)
Loading

Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted May 15, 2015, 6:09 PM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted May 15, 2015, 8:23 PM EDT
Sorting a list of items in a list box
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);
}
Nanhe SiddiqueRank #1,103 · 1.7K reputationPosted May 15, 2015, 8:35 PM EDT
ArrayList ListBoxArray = new ArrayList(); //add the Items to ArrayList without sort for (int i = 0; i CarNameListBox.Items.Count; i++ ) { ListBoxArray.Add(CarNameListBox.Items[i].Value); } // Clear the Data and add soterd Items to the List Box CarNameListBox.Items.Clear(); ListBoxArray.Sort(); CarNameListBox.DataSource = ListBoxArray; CarNameListBox.DataBind(); it may help youAkhil GargRank #772 · 3K reputationPosted May 15, 2015, 8:51 PM EDT
Manoj BhoirRank #599 · 4K reputationPosted May 15, 2015, 8:52 PM EDT
You can either use ListBox.Sort Method.
Sort forces the collection to add each item back to itself if the Sorted property is true. Each item is then inserted into the correct position.
Or you can simply add Items of First ListBox into List
I hope this will help you.
Masoud A30 reputationPosted May 16, 2015, 11:07 AM EDT