2013-08-06 85 views
0

我有一個包含'System.Windows.Forms.CheckedListBox'對象的PowerShell窗體。目前我能夠一次選擇不止一個複選框選項更多:PowerShell CheckedListBox一次只能選擇一個選項

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 

回答

0

你試過更改selectionMode屬性 「一」?

$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) 
+0

我試過'SelectionMode =「One」'但這不起作用。單選按鈕是個好主意。你知道如何在同一個表單中設置兩組單選按鈕組(都只允許一個選擇)嗎? – Richard

+0

同一父級中的RadioButton會自動分組。所以,如果你把兩個組放入兩個不同的Panel容器中,那就可以工作。還有GroupBox控件,但是會在組中繪製邊框。 '$ groupBox = New-Object System.Windows.Forms.GroupBox' – Antony

+0

創建不同的面板容器完美地工作,謝謝。 – Richard