문제

I Have a PowerShell form that contains a 'System.Windows.Forms.CheckedListBox' object. Currently I am able to select more than one checkbox option at a time:

CheckedListBox with 2 selected

Is there a easy way of making the CheckedListBox only allow one selection?

CheckedListBox with 1 selected

or will I have to use some 'onClick' event logic within my script?

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
도움이 되었습니까?

해결책

Have you tried changing the SelectionMode attribute to "One"?

$checkedlistbox2.SelectionMode = "One"

Alternatively, you could use a radio button control, which allows only one selection at a time? Something like this:

$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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top