首页 > 解决方案 > PowerShell Out-GridView 处理 Click/DoubleClik 事件

问题描述

将数据发送到 GridView (Out-GridView) 后

如何创建处理行单击(行选择)的事件

或处理双击并关闭
在变量中提供所选行的 GridView 的事件

TIA

标签: powershellgridviewevent-handling

解决方案


不幸的是,我认为没有“行选择事件” Out-GridView,也没有双击列表中项目的方法。

但是,此示例显示了如何使用Out-GridView. 通过Out-GridViewCmdLet 管道传输数据并使用-PassThru开关允许用户选择项目。PassThru这意味着-Wait挂起脚本并等待用户选择项目或关闭窗口:

$viewme = @('pick','one','of','these')

$selection = $viewme | Out-GridView -PassThru -Title 'Pick item(s)'

如果我单击Cancel或关闭窗口,则$selection变量为空:

$selection -eq $null
True

否则,如果我确实选择了项目,它们将在类型的对象中返回System.Array

$selection
one
these

推荐阅读