Reputation: 85
I have data in my combobox1 and was wondering if it would be possible to sort the data in the combobox alphabetically?
I have spent ages trying to find the answer by searching the forum but couldnt find anything, I would really appreciate your help..
With ComboBox2
.DisplayMember = "Name"
.ValueMember = "FullName"
.DataSource = New IO.DirectoryInfo("Path").GetFiles() _
.Select(Function(fi) New With {.Name = _
IO.Path.GetFileNameWithoutExtension(fi.FullName), fi.FullName}) _
.ToArray()
End With
Upvotes: 4
Views: 8366
Reputation: 7273
Sort your data first, then bind it to your combobox.
With ComboBox1
.DisplayMember = "Name"
.ValueMember = "FullName"
.DataSource = New IO.DirectoryInfo("C:\asdf").GetFiles() _
.Select(Function(fi) New With {.Name = _
IO.Path.GetFileNameWithoutExtension(fi.FullName), fi.FullName}) _
.OrderBy(Function(fi) CType(fi.Name, Integer)) _
.ToArray()
End With
Upvotes: 3
Reputation: 1
select the property "data source" for the combobox and click at the triple dots, a query will be shown, then sort the field in Ascending order save all and restart the database, good luck,,
Waleed
Upvotes: -1
Reputation: 8982
Could you just add a .orderby LINQ predicate where you set the data source?
.DataSource = unsorted.Select( ... ).OrderBy(Function(x) x.name).ToArray()
Upvotes: 0