PowerShell CheckedListBox一次只能选择一个选项

时间:2013-08-06 09:12:35

标签: forms powershell checklistbox

我有一个包含'System.Windows.Forms.CheckedListBox'对象的PowerShell表单。目前,我一次可以选择多个复选框选项:

CheckedListBox with 2 selected

是否有一种简单的方法可以让CheckedListBox只允许一个选择?

CheckedListBox with 1 selected

还是我必须在我的脚本中使用一些'onClick'事件逻辑?

CheckListBox Proteries:

$checkedlistbox2.BackColor = 'Control'
$checkedlistbox2.BorderStyle = 'None'
$checkedlistbox2.CheckOnClick = $True
$checkedlistbox2.ColumnWidth = 56
$checkedlistbox2.FormattingEnabled = $True
[void]$checkedlistbox2.Items.Add("W2K")
[void]$checkedlistbox2.Items.Add("WXP")
[void]$checkedlistbox2.Items.Add("WS7")
$checkedlistbox2.Location = '107, 284'
$checkedlistbox2.MultiColumn = $True
$checkedlistbox2.Name = "checkedlistbox2"
$checkedlistbox2.SelectionMode = 'None'
$checkedlistbox2.Size = '192, 15'
$checkedlistbox2.TabIndex = 66

1 个答案:

答案 0 :(得分:0)

您是否尝试将SelectionMode属性更改为“One”?

$checkedlistbox2.SelectionMode = "One"

或者,您可以使用单选按钮控件,一次只允许一个选项?像这样:

$radioButton1 = New-Object System.Windows.Forms.RadioButton
$radioButton2 = New-Object System.Windows.Forms.RadioButton
$radioButton1.Checked = $True
$radioButton1.Name = "W2K"
$radioButton1.Text = "W2K"
$radioButton1.Location = New-Object System.Drawing.Point(10,10)
$radioButton2.Name = "WXP"
$radioButton2.Text = "WXP"
$radioButton2.Location = New-Object System.Drawing.Point(10,30)
$form.Panel1.Controls.Add($radioButton1)
$form.Panel1.Controls.Add($radioButton2)