How to sort a ListBox

0

I have a listBox and two buttons on the side, one to move up and the other down the selected item. However, the list is loaded by the DataSource of a table of the bank, wanted to sort the position of the list items, because after ordering I will save those items in another table.

I saw that it has moveNext , but it does not change the position, it just changes the selection.

 private void btnSobe_Click(object sender, EventArgs e)
 {
     bdsCliente.MoveFirst();
 }

 private void btnDesce_Click(object sender, EventArgs e)
 {
     bdsCliente.MoveLast();
 }
    
asked by anonymous 12.11.2014 / 20:54

1 answer

1

You can sort the list with Linq and then assign the sorted list as ListView data source again.

It would be something like this:

private void btnOrdenaListView_Click(object sender, EventArgs e)
{
     // Ordena a lista por um campo aleatório.
     var registrosOrdenados = listView.DataSource.OrderBy(x => x.Id);

     listView.DataSource = registrosOrdenados;
}
    
24.07.2015 / 17:56