I am kinda' new to Powershell and have searched the ends of the earth for a solution, but I can't seem to find anything. I hope it's still doable.
I am trying to sort a CollectionView
by date that's in string format. In my custom sorter, I want to convert the date strings (M/dd/yyyy) into Date objects and have the Comparer
sort it by date. My CollectionView
is filled like this:
$stuff = [System.Collections.ObjectModel.ObservableCollection[System.Object]](ImportClixml -Path $path)
$view = [System.Windows.Data.CollectionView]([System.Windows.Data.CollectionViewSource]::GetDefaultView($stuff))
The XML
data is filled with Properties
that are String
and Boolean
values. the Date value I am trying to sort is a String
. The CollectionView
is the bound to a DataGrid
like so: $myDataGrid.ItemsSource = $myCollectionView
Can I just make a function that sorts and just point to it somehow?
function customSorter{ #Do Stuff }
$myCollectionView.CustomSort = customSorter
The CustomSort
property takes in a System.Collections.IComparer
object. I'm not sure how to approach this. I would prefer to just keep it all in powershell 4 and not import C# code or something like that. Any help is appreciated.