Datagridview double sort

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
structispdt
Posts: 1
Last visit: Fri Mar 15, 2024 1:26 am

Datagridview double sort

Post by structispdt »

Hi,
I know to sort Datagridview using one column :
$datagridview.Sort($datagridview.Columns[0], 'Ascending')

But I would like to sort a Datagridview using 2 columns.

Data sample:

Status | Name
ON | App1
OFF | App2
OFF | App3
ON | App4

If I sort using first column (Status), second column is not sorted for example :
Status | Name
ON | App1
ON | App4
OFF | App3
OFF | App2

Regards.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datagridview double sort

Post by jvierra »

Default column sort can only sort the column chosen. To sort on more than one column set the "RowSort" properties to the rows to be sorted.
  1. ([System.Data.DataTable]$datagridview1.DataSource).DefaultView.Sort = 'Field1 ASC,Filed2 ASC'
Field1 and Field2 are the names of the datatable fields.

See: https://msdn.microsoft.com/en-us/librar ... .110).aspx
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked