Home > front end >  I am trying to show csv totals on a datagridview
I am trying to show csv totals on a datagridview

Time:01-10

I am trying to show csv totals on a datagridview but it doesn't seem to like it. please see below code

$button70_Click = {
$rows = Import-Csv -Path "C:\Users\Name\Desktop\Testsdarts\301leader.csv" 
$rows | Group-Object Player | 
Select-Object Name, @{ n='Wins'; e={ ($_.Group | Measure-Object Wins -Sum).Sum } }
$dataGridView1.DataSource=[System.Collections.ArrayList]$rows
}

please see below how my csv is laid out

enter image description here

as you can see it works perfectly in Powershell ISE

enter image description here

but the datagridview doesn't, is there any way to get the ISE output in the datagridview?

enter image description here

CodePudding user response:

Looking at the code, the gridview takes its input data from the $rows variable - so you need to ensure you actually store the output from the Group-Object/Select-Object pipeline in $rows by using the = assignment operator:

$rows = $rows | Group-Object Player | Select-Object Name, @{ n='Wins'; e={ ($_.Group | Measure-Object Wins -Sum).Sum } }
# ^ remember to assign the modified data back to the variable
  • Related