Как изменить первый столбец на check box

Please help 🙁

My understanding is i need to modify the $checkListBox.add_ItemCheck event handler, but i can’t wrap my brain around how i would do that, whilst retaining the existing behaviour.

Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(300, 200)
$checkListBox = New-Object System.Windows.Forms.CheckedListBox
$checkListBox.Location = New-Object System.Drawing.Point(10, 10)
$checkListBox.Size = New-Object System.Drawing.Size(200, 150)
# Add items to the checkListBox
$checkListBox.Items.Add("Option 1") | Out-Null
$checkListBox.Items.Add("Option 2") | Out-Null
$checkListBox.Items.Add("Option 3") | Out-Null
$checkListBox.SelectionMode = 'One'
$checkListBox.CheckOnClick = $true
$checkListBox.SetItemChecked(0, $true) # set the first item by default.
# Add ItemCheck event handler
$checkListBox.add_ItemCheck({ param($sender, $e) foreach ($index in $checkListBox.CheckedIndices) { if ($index -ne $e.Index) { $checkListBox.SetItemChecked($index, $false) } }
})
$form.Controls.Add($checkListBox)
$form.ShowDialog() | Out-Null

Example of me running the above code

Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(300, 200)
$checkListBox = New-Object System.Windows.Forms.CheckedListBox
$checkListBox.Location = New-Object System.Drawing.Point(10, 10)
$checkListBox.Size = New-Object System.Drawing.Size(200, 150)
("Option 1","Option 2","Option 3") | % {$checkListBox.Items.Add("$_") | Out-Null}
$checkListBox.SelectionMode = 'One'
$checkListBox.CheckOnClick = $true
$checkListBox.SetItemChecked(0, $true) # set the first item by default.
$handlingEvent = $false
$checkListBox.add_ItemCheck({ param($sender, $e) if ($handlingEvent) { return } $handlingEvent = $true try { $currentCheckedState = [System.Windows.Forms.CheckState]::Unchecked $newCheckedState = [System.Windows.Forms.CheckState]::Unchecked if ($e.CurrentValue -eq 1) { $currentCheckedState = [System.Windows.Forms.CheckState]::Checked } if ($e.NewValue -eq 1) { $newCheckedState = [System.Windows.Forms.CheckState]::Checked } if ($currentCheckedState -eq [System.Windows.Forms.CheckState]::Checked -and $newCheckedState -eq [System.Windows.Forms.CheckState]::Unchecked) { $e.NewValue = [System.Windows.Forms.CheckState]::Checked } $checkListBox.CheckedIndices | ForEach-Object { if ($_ -ne $e.Index) { $checkListBox.SetItemChecked($_, $false) } } } finally { $handlingEvent = $false }
})
$form.Controls.Add($checkListBox)
# Show the form, but since we only seem to get "cancel" in the resultant object, no point keeping it. we only care what checkbox they selected..
$form.ShowDialog() | out-null
# Output the result
$DialogOut = $checkListBox.CheckedItems
Write-host "User Selected: $DialogOut"
$sqlSelect = "SELECT ip, computername, os, OSArchitecture, username, domain FROM computers;"
$processes = Invoke-DB -sqlSelect $sqlSelect
Update-DataGridView -DataGridView $datagridviewResults -Item $processes -AutoSizeColumns DisplayedCells

Результат запроса выводится функцией, которая выводит данные в виде таблицы:

function Update-DataGridView
{	<#	.SYNOPSIS	This functions helps you load items into a DataGridView.	.DESCRIPTION	Use this function to dynamically load items into the DataGridView control.	.PARAMETER DataGridView	The DataGridView control you want to add items to.	.PARAMETER Item	The object or objects you wish to load into the DataGridView's items collection.	.PARAMETER DataMember	Sets the name of the list or table in the data source for which the DataGridView is displaying data.	.PARAMETER AutoSizeColumns Resizes DataGridView control's columns after loading the items.	#>	Param (	[ValidateNotNull()]	[Parameter(Mandatory = $true)]	[System.Windows.Forms.DataGridView]$datagridviewResults,	[ValidateNotNull()]	[Parameter(Mandatory = $true)]	$Item,	[Parameter(Mandatory = $false)]	[string]$DataMember,	[System.Windows.Forms.DataGridViewAutoSizeColumnsMode]$AutoSizeColumns = 'None'	)	$datagridviewResults.SuspendLayout()	$datagridviewResults.DataMember = $DataMember	if ($null -eq $Item)	{	$datagridviewResults.DataSource = $null	}	elseif ($Item -is [System.Data.DataSet] -and $Item.Tables.Count -gt 0)	{	$datagridviewResults.DataSource = $Item.Tables[0]	}	elseif ($Item -is [System.ComponentModel.IListSource]`	-or $Item -is [System.ComponentModel.IBindingList] -or $Item -is [System.ComponentModel.IBindingListView])	{	$datagridviewResults.DataSource = $Item	}	else	{	$array = New-Object System.Collections.ArrayList	if ($Item -is [System.Collections.IList])	{	$array.AddRange($Item)	}	else	{	$array.Add($Item)	}	$datagridviewResults.DataSource = $array	}	if ($AutoSizeColumns -ne 'None')	{	$datagridviewResults.AutoResizeColumns($AutoSizeColumns)	}	$datagridviewResults.ResumeLayout()
}

Вот так выгляди результат вывода:
65bb585fd2e9c955262222.png
Подскажите пожалуйста, как мне заменить первый столбец со стрелкой на Чекбоксы, чтобы можно было выбирать несколько компьютеров в разнобой.
Чтобы было так:
65bb591581506552816162.png

:/>  3 простых способа перезагрузить компьютер через Интернет

Заранее благодарю за вашу помощь.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(460,350)
$Form.Text ="Pass info"
$Form.AutoSize = $false
$Form.MaximizeBox = $false
$Form.MinimizeBox = $true
$Form.BackColor = "#c08888"
$Form.ShowIcon = $true
$Form.SizeGripStyle = [System.Windows.Forms.SizeGripStyle]::Hide
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D
$Form.WindowState = "Normal"
$Form.StartPosition = "CenterScreen"
$Form.Opacity = 1.0
$Form.TopMost = $false
############################################## Function start ##############################################
function Info {
$wks=$InputBox.text;
Write-Host $wks
$regex1 = "[^-a-zA-Z0-9_#.!@]+"
$regex2 = "[^-а-яА-Я0-9_#.!@]+"
If($wks -match $regex2) {
$Result1=Get-ADUser -identity $wks -Properties * | select CN -ExpandProperty CN
$outputBox.text=$Result1
$Result2=Get-ADUser -identity $wks -Properties * | select PasswordLastset -ExpandProperty PasswordLastset
$outputBox2.text=$Result2
}
If($wks -match $regex1) {
$wks2 = "$wks*"
Write-Host $wks2
$Result3=Get-AdUser -Filter 'name -Like $wks2' | Select Name -expandproperty Name| Sort Name | fl | out-string
Write-Host $Result3
$ListBox.text = $Result3
}
}
############################################## End Function ##############################################
############################################## GroupBox ##############################################
$groupBox = New-Object System.Windows.Forms.GroupBox
$groupBox.Location = New-Object System.Drawing.Size(10,230)
$groupBox.size = New-Object System.Drawing.Size(280,80)
$groupBox.text = "Info:"
$Form.Controls.Add($groupBox)
$FormLabel1 = New-Object System.Windows.Forms.Label
$FormLabel1.Text = "User AD:"
$FormLabel1.ForeColor = "#3009f1"
$FormLabel1.Font = "Microsoft Sans Serif,8"
$FormLabel1.Location = New-Object System.Drawing.Point(10,10)
$FormLabel1.AutoSize = $true
$Form.Controls.Add($FormLabel1)
$FormLabel2 = New-Object System.Windows.Forms.Label
$FormLabel2.Text = "ФИО:"
$FormLabel2.Location = New-Object System.Drawing.Point(10,25)
$FormLabel2.ForeColor = "#3009f1"
$FormLabel2.Font = "Microsoft Sans Serif,8"
$FormLabel2.AutoSize = $true
$groupBox.Controls.Add($FormLabel2)
$FormLabel3 = New-Object System.Windows.Forms.Label
$FormLabel3.Text = "Дата:"
$FormLabel3.Location = New-Object System.Drawing.Point(10,47)
$FormLabel3.ForeColor = "#3009f1"
$FormLabel3.Font = "Microsoft Sans Serif,8"
$FormLabel3.AutoSize = $true
$groupBox.Controls.Add($FormLabel3)
############################################## End GroupBox ##############################################
############################################ InputBox and OutputBox #########################################
$InputBox = New-Object System.Windows.Forms.TextBox
$InputBox.Location = New-Object System.Drawing.Size(65,5)
$InputBox.Size = New-Object System.Drawing.Size(150,20)
$Form.Controls.Add($InputBox)
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(80,20)
$outputBox.Size = New-Object System.Drawing.Size(180,20)
$outputBox.ReadOnly = $True
$groupBox.Controls.Add($outputBox)
$outputBox2 = New-Object System.Windows.Forms.TextBox
$outputBox2.Location = New-Object System.Drawing.Size(80,42)
$outputBox2.Size = New-Object System.Drawing.Size(180,42)
$outputBox2.ReadOnly = $True
$groupBox.Controls.Add($outputBox2)
############################################ End InputBox and OutputBox #########################################
############################################## ListBox ##############################################
$ListBox = New-Object System.Windows.Forms.TextBox
$ListBox.Location = New-Object System.Drawing.Size(65,30)
$ListBox.Size = New-Object System.Drawing.Size(220,200)
$ListBox.MultiLine = $True #declaring the text box as multi-line
$ListBox.AcceptsReturn = $true
$ListBox.ScrollBars = "Vertical"
$ListBox.AcceptsTab = $true
$ListBox.WordWrap = $True
$ListBox.ReadOnly = $True
$Form.Controls.Add($ListBox)
############################################## End ListBox ##############################################
############################################## search in Russian and in English ##############################################
$regex1 = "[^-a-zA-Z0-9_#.!@]+"
$regex2 = "[^-а-яА-Я0-9_#.!@]+"
$TestName = "Mouse" # Cat или кот
If($TestName -match $regex1){echo "English '$TestName'"}
If($TestName -match $regex2){echo "Русский '$TestName'"}
get-aduser -filter 'name -like "*" ' | select name -expandproperty name
############################################## End search in Russian and in English ##############################################
############################################## Button ##############################################
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(310,20)
$Button.Size = New-Object System.Drawing.Size(110,80)
$Button.Text = "Загрузить данные"
$Button.BackColor = "#d7f705"
$Button.Add_Click({Info})
$Form.Controls.Add($Button)
############################################## End Button ##############################################
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()

введите сюда описание изображения