powershell - 在powershell studio中清除复选框列表中的复选框

标签 powershell checkboxlist

我创建了一个巨大的复选框列表,我需要一个按钮来清除所有选中的项目。这是我所拥有的:

 $btnResetGroups_Click = {
    foreach ($chkbox in $chklistGroups)
    {
        $chkbox.ClearSelected() # I tried to do $chkbox.Checked = $false but it doesn't recognize 'checked' as a property
    }

    #   $chklistGroups.ClearSelected()
}

这不起作用有什么原因吗?

编辑:这是填充复选框列表的代码:

$formPTINewUserCreation_Load={
    Import-Module ActiveDirectory

    # read in the XML files
    [xml]$NewUserXML = Get-Content -LiteralPath \\papertransport.com\files\UserDocuments\mneis\Code\XML\NewUserTest.xml

    # popoulate the checklist with the groups from active directory
    $AD_ResourceGroups = Get-ADGroup -filter * -SearchBase "OU=Resource Groups,OU=Groups,OU=Paper Transport,DC=papertransport,DC=com"
    $AD_ResourceGroups | ForEach-Object { $chklistGroups.Items.Add($_.name) }
}

This is the GUI itself:

最佳答案

为了确保单击按钮时每个复选框都未被选中,代码必须循环遍历包含复选框的容器。

$btnResetGroups_Click = {
    # get the container (in this case it looks like a list box)
    $myCheckBoxes = $myListBox.Items
    # next loop through each checkbox in the array of checkbox objects
    foreach ($chkbox in $myCheckBoxes)
    {
        $chkbox.Checked = $false
    }
}

这将确保容器中的每个复选框都设置为 false。从 GUI 的风格来看,我假设这是 WPF 而不是 Winform。

关于powershell - 在powershell studio中清除复选框列表中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45551270/

相关文章:

r - 表或数据框上的复选框

javascript - 使用 AngularJS 或 Javascript 在选择列表中创建复选框

c# - 从数据库中保存/检索/比较 CheckboxList 值

c# - 一行清除 CheckBoxList

html - powershell ConvertTo-Html 添加类

regex - 重命名文件时使用Move-Item,并使用正则表达式 “cleaning”文件名

c# - string.Join 对于逗号分隔值

powershell - 使用 PowerShell 正确读取 UTF-8 文件

powershell - 通过 PowerShell 获取 Azure VM 详细信息

multithreading - 在 powershell 中使用多线程一次调用多个 URL