在 powershell studio 中清除复选框列表中的复选框
Clearing checkboxes in a checkedboxlist in powershell studio
我创建了一个巨大的复选框列表,我需要一个按钮来清除所有选中的项目。这是我拥有的:
$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) }
}
为了确保在单击按钮时取消选中每个复选框,代码必须循环遍历包含复选框的容器。
$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。
我创建了一个巨大的复选框列表,我需要一个按钮来清除所有选中的项目。这是我拥有的:
$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) }
}
为了确保在单击按钮时取消选中每个复选框,代码必须循环遍历包含复选框的容器。
$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。