user1413746
user1413746

Reputation: 85

how to sort data in my combobox

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

Answers (4)

FarFigNewton
FarFigNewton

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

Waleed
Waleed

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

jrq
jrq

Reputation: 31

set the .Sorted property to TRUE

Upvotes: 3

Jeff B
Jeff B

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

Related Questions