private void cboEventFilter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem item = cboEventFilter.SelectedItem as ComboBoxItem;
switch (item.Content)
{
case "Date":
//Original method
datActiveEvents.ItemsSource = _eventManager.RetreieveActiveEvents();
//Something like this line commented out
//datActiveEvents.ItemsSource = _eventManager.RetreieveActiveEvents().OrderBy<EventDateID>;
break;
case "Time":
MessageBox.Show("Time filter selected");
break;
case "Name":
MessageBox.Show("Event Name filter selected");
break;
case "Sublocation":
MessageBox.Show("Sublocation filter selected");
break;
}
}
CodePudding user response:
If the return type of RetreieveActiveEvents()
is an IEnumerable<T>
, you could use the OrderBy
LINQ extension method:
datActiveEvents.ItemsSource = _eventManager.RetreieveActiveEvents()
.OrderBy(x => x.EventDateID);
If the return type is a non-generic IEnumerable
, you could use the Cast
extension method to convert it to an IEnumerable<T>
before you sort the results:
datActiveEvents.ItemsSource = _eventManager.RetreieveActiveEvents()
.Cast<YourClassWithTheEventDateIDProperty>()
.OrderBy(x => x.EventDateID);