代码之家  ›  专栏  ›  技术社区  ›  Matt

在powershell studio中清除checkedboxlist中的复选框

  •  2
  • Matt  · 技术社区  · 7 年前

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

    1 回复  |  直到 7 年前
        1
  •  4
  •   Jason Snell    7 年前

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