Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell set default sorting on datagrid

So i have this wpf datagrid whose columns are defined in a xaml file,
i programmatically check data and insert rows in it 1 by 1 after a button is pressed.

I’m trying to understand how i can populate it and set a sorting (the same sorting as i would have clicking on a column header)

in winforms i used to add:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$myDataGrid.Sort($myDataGrid.Columns[3],'Ascending')

after my populating function.

How do i replicate that in WFP (and powershell)?

i did try:

$Datagrid.Items.SortDescription.Add([pscustomobject]@{ColumnName="MyColumn";SortDirection="ListSortDirection.Ascending"})

but i’m having quite some trouble as i only find c# explanations and trying to adapt is not working out….

>Solution :

Try this:

$sortDescription = New-Object System.ComponentModel.SortDescription('MyColumn', 'Ascending')
$Datagrid.Items.SortDescriptions.Add($sortDescription)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading