You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将PowerShell ISE中CSV统计结果显示到DataGridView?

问题解决方法

你的代码核心问题是:统计后的结果没有被保存并绑定到DataGridView,只是在控制台输出了,最后绑定的还是原始的CSV数据。

修正后的代码如下:

$button70_Click = {
    $rows = Import-Csv -Path "C:\Users\Name\Desktop\Testsdarts\301leader.csv" 
    # 将统计结果存入$stats变量,而不是直接输出
    $stats = $rows | Group-Object Player | 
             Select-Object Name, @{ n='Wins'; e={ ($_.Group | Measure-Object Wins -Sum).Sum } }
    # 绑定统计后的结果到DataGridView
    $dataGridView1.DataSource = [System.Collections.ArrayList]$stats
}

关键说明:

  • 用$stats变量接收Group-Object和Select-Object处理后的统计结果,确保数据能被后续的DataGridView调用。
  • 转为System.Collections.ArrayList是为了适配DataGridView的数据源要求,避免直接使用PSCustomObject数组可能出现的绑定问题。

内容的提问来源于stack exchange,提问作者RISL2023

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 09:15:32