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

I am trying to show csv totals on a datagridview

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

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

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

>Solution :

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
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