DataGridView + sorted column

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 11 years and 7 months 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.
User avatar
BrunoG
Posts: 2
Last visit: Mon Jul 08, 2019 1:41 am

DataGridView + sorted column

Post by BrunoG »

Hello,

I'm trying to sort a column in a dataGridView but i find not the solution.
I load the dataGridView with the function " Load-dateGridView ".

exemple in my code :


[array]$list = Function_listefichier -path $path

Load-dataGridView -DataGridView $main_datagridview -Item list
Here, $list is an array of file with several properties.
The dataGridView is loaded but impossible to sort the columns when i click on the column header. In my code I try :
$main_datagridview.Columns | foreach { $_.SortMode = 'automatic' }

But it does not work.

thank's for your help.

Bruno
FRANCE
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

DataGridView + sorted column

Post by davidc »

The easiest way to do this is to sort the original list and then reload it into the DataGridView. Do to data binding and PowerShell it becomes too complicated to handle it via the Datagridview unless you manually build the grid. David
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

DataGridView + sorted column

Post by davidc »

The latest PowerShell Studio v3.0.8 has a template for sorting the DataGridView. You might want to take a look at it. David
David
SAPIEN Technologies, Inc.
User avatar
BrunoG
Posts: 2
Last visit: Mon Jul 08, 2019 1:41 am

DataGridView + sorted column

Post by BrunoG »

Finaly i created in my code an event "ColumnHeaderMouseClick" like this :

$main_datagridview_ColumnHeaderMouseClick=System.Windows.Forms.DataGridViewCellMouseEventHandler]{

if ( ( $GLOBAL_tabSortColonne[$_.ColumnIndex] -eq 'pasTrie' ) -or ( $GLOBAL_tabSortColonne[$_.ColumnIndex] -eq 'descending' ) )
{ $tempTrie=$true ; $global:GLOBAL_tabSortColonne[$_.ColumnIndex] = 'ascending' }
elseif ( $GLOBAL_tabSortColonne[$_.ColumnIndex] -eq 'ascending' )
{ $tempTrie=$false ; $global:GLOBAL_tabSortColonne[$_.ColumnIndex] = 'descending' }

$listResultats = $listResultats | Sort-Object -Property $GLOBAL_tabColonneIndex[$_.ColumnIndex] -Descending:$tempTrie

Load-DataGridView -DataGridView $main_datagridview -Item $listResultats
}
I'm going to install the new version v3.0.8 in order to see the template for sorting the DataGridView.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

DataGridView + sorted column

Post by davidc »

As long as it works :). The template converts the data into a DataTable, which adds an extra step but it is still worth reviewing.David
David
SAPIEN Technologies, Inc.
This topic is 11 years and 7 months 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.