Reputation: 35
let's say i have a list with this records in ("Germany", "Belgium", "Netherlands", "Spain", "Russia", "Italy").
And i want to order this list with "Belgium" on top of the list.
So that when i load this list into a ComboBox "Belgium" is the selectedvalue by load.
Now how do i order the rest of the list?
This is what i have: "Belgium" comes at the top but the rest is not ordered.
return Enumerable.Select(GetTable()
.OrderByDescending(o => o.Name == country)
.ThenBy(o => o.Name != country), b =>
new ComboBoxBase.ComboBoxListStructGuid { Id = b.CountryID, Description = b.Country }).ToList();
Upvotes: 2
Views: 47
Reputation: 21477
return Enumerable.Select(GetTable()
.OrderByDescending(o => o.Name == country)
.ThenBy(o => o.Name), b =>
new ComboBoxBase.ComboBoxListStructGuid { Id = b.CountryID, Description = b.Country }).ToList();
Upvotes: 1
Reputation: 46947
var countries = new List<string>(){ "Germany", "Belgium", "Netherlands", "Spain", "Russia", "Italy" };
var result = countries
.OrderByDescending (c => c == "Belgium")
.ThenBy (c => c);
Upvotes: 4