EspertoDiProgrammazione EspertoDiProgrammazione - 1 month ago 7
Vb.net Question

How to sort a team data in alphabet order

I've a table like this:

Dim Classifica_Table() As Team_Data


I want to order the table in alphabet mode, in particular, this table contains all team of a championship grabbed by webpage.

This value are inserted in a Combobox:

For Each Team As Team_Data In Classifica_Table
ComboBox1.Items.Add(Team.Name) 'Populate Combo Boxes with team names
Next


but the order isn't good for me, so I want sort in alphabet.
How can I do this? I tried with
Classifica_Table.Sort()
but seems doesn't working, the compiler tells me: that nothing Sort() accept this argument number.

Answer

You could use the IEnumerable extension OrderBy

For Each Team As Team_Data In Classifica_Table.OrderBy(Function(x) x.Name)
    ComboBox1.Items.Add(Team.Name) 
Next