how to sort data in my combobox

.net, vb.net

Solution

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

Problem

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 ```

Original source

Related problems