I know that the topic has already been discussed several times and I have read a few posts in this forum on the topic, but I still don't get smarter and need help.
I have to sort the individual columns of a datagrid view and have read that this is only possible if the datagrid view is a DataTable.
This is what I do.
1. I have a function that reads out AD computers and then creates a new PSCustomobject.
2. I convert this object afterwards with' Convertto-DataTable'.
3. then I fill the datagridview with' Update-DataGridview'.
Code: Select all
$btnADComputer_Click={
$GHComputer = Get-GHComputer
$Datatable = ConvertTo-DataTable -InputObject $GHComputer
Update-DataGridView -DataGridView $datagridview -Item $GHComputer -AutoSizeColumns AllCells
}
I want to use a 'ColumnHeaderMouseDoubleClick' event for sorting.
(http://www.lazywinadmin.com/2015/01/pow ... dview.html)
Code: Select all
$datagridview_ColumnHeaderMouseDoubleClick=[System.Windows.Forms.DataGridViewCellMouseEventHandler]{
# [System.Windows.Forms.MessageBox]::Show("Hallo") ##DEBUG
$column = $datagridview.Columns[$_.ColumnIndex]
$direction = [System.ComponentModel.ListSortDirection]::Ascending
if ($column.HeaderCell.SortGlyphDirection -eq 'Descending')
{
$direction = [System.ComponentModel.ListSortDirection]::Descending
}
$datagridview.Sort($datagridview.Columns[$_.ColumnIndex], $direction)
}
Unfortunately I get the error message :
"DataGridView control must be bound to an IBindingList object to be sorted."
Of course, I found a lot of information about this on the internet, but this is where my understanding ends.
Apparently I have to save the datagridview again, bind it to a BindingList, sort it and print it again....
I need help with the implementation using an example, if possible.
Thank you very much for your help