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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
BrunoG
Posts: 2
Joined: Thu Jul 26, 2012 9:36 pm

DataGridView + sorted column

Post by BrunoG » Thu Jul 26, 2012 9:36 pm

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
Joined: Thu Aug 18, 2011 4:56 am

DataGridView + sorted column

Post by davidc » Fri Jul 27, 2012 4:55 am

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
Joined: Thu Aug 18, 2011 4:56 am

DataGridView + sorted column

Post by davidc » Thu Aug 16, 2012 10:43 am

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
Joined: Thu Jul 26, 2012 9:36 pm

DataGridView + sorted column

Post by BrunoG » Mon Aug 20, 2012 1:59 am

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
Joined: Thu Aug 18, 2011 4:56 am

DataGridView + sorted column

Post by davidc » Mon Aug 20, 2012 4:20 am

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.