If you wanted to make PurgeListOfStudies a little more type safe, you could make it take a parameter of type IEnumerable<ListViewItem>
like so:
private void PurgeListOfStudies(IEnumerable<ListViewItem> items)
{
/// process items in the list...
}
and call it like this:
PurgeListOfStudies(myStudiesPageCurrent.ListView.Items.OfType<ListViewItem>());
or this:
PurgeListOfStudies(myStudiesPageCurrent.ListView.SelectedItems.OfType<ListViewItem>());
The OfType<ListViewItem>()
extension method turns a non-generic IEnumerable
into the more type safe IEnumerable<ListViewItem>
.
Edit:
If you're annoyed by having to explicitly call OfType<ListViewItem>()
you could add extension methods to ListView:
static class ListViewExtensions
{
public static IEnumerable<ListViewItem> SelectedListViewItems(this ListView listView)
{
return listView.SelectedItems.OfType<ListViewItem>();
}
public static IEnumerable<ListViewItem> ListViewItems(this ListView listView)
{
return listView.Items.OfType<ListViewItem>();
}
}
and then call
PurgeListOfStudies(myStudiesPageCurrent.ListView.ListViewItems());
or
PurgeListOfStudies(myStudiesPageCurrent.ListView.SelectedListViewItems());