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

问题描述 投票:0回答:2

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

 $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) }
}

powershell checkboxlist
2个回答
4
投票

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

$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 而不是 Winforms。


0
投票

这对我有用

$DataCheckbox.Add_click({

    $BoxState = $DataCheckbox.CheckState
    
    if($BoxState -eq $false)
    {
      $DataCheckbox.Checked = $false
    }
    else
    {
      $DataCheckbox.Checked = $true
    }

})

© www.soinside.com 2019 - 2024. All rights reserved.