I have a listbox with list item values like B1, B2,…B7000…etc. Everytime when items get appended to the listbox, I need to sort the whole listbox.
At the moment, they are sorted in this way B1, B100, B1000, B2, B200 etc which is not logical.
How can I sort so that it is like B1, B2, B3….?
I’ve been trying to use LINQ but it doesn’t work:
List<ListItem> list = new List<ListItem>(ListBox7.Items.Cast<ListItem>());
list = list.OrderBy(li => li.Text).ToList<ListItem>();
ListBox7.Items.Clear();
ListBox7.Items.AddRange(list.ToArray<ListItem>());
Please help! I’ve looked everywhere and could not find a solution!
1 Answer