Sort ListLox ListItems with LINQ?

I am trying to sort items in a ListBox. However, after that the Item value gets the Item Text value. Any help would be appreciated.

lbxCustomers.DataSource = lbxCustomers.Items.Cast<ListItem>().Reverse().ToList(); lbxCustomers.DataBind(); 
+4
source share
3 answers

Perhaps you should first save the list to a shared collection, and then sort it. Something like that:

 List<ListItem> list = new List<ListItem>(lbxCustomers.Items.Cast<ListItem>()); list = list.OrderBy(li => li.Text).ToList<ListItem>(); lbxCustomers.Items.Clear(); lbxCustomers.Items.AddRange(list.ToArray<ListItem>()); 
+3
source

Try resetting the DisplayMember and ValueMember the Listbox after installing the DataSource. Many times, if the control is already bound and you set the DataSource again, it disables the DisplayMember / ValueMember properties.

0
source

Try sorting the list separately. In the next step, specify the value "Text" and "Data". Databind control.

0
source

Source: https://habr.com/ru/post/1413592/


All Articles