vendredi 22 septembre 2017

Add Checkbox to Header Cell in Datagridview

I have a form with a datagridview on it. In the first column of this datagridview is a CheckBoxColumn. I am trying to add a checkbox to the header of the first column to act as a select all for the checkboxes below it. I can't understand the C# examples I've found online and I haven't found any PowerShell examples. Can someone point me in the right direction of how to do this?

[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(400, 400)
$form.KeyPreview = $true

$CheckBoxColumn1 = New-object System.Windows.Forms.DataGridViewCheckBoxColumn
$CheckBoxColumn1.Width = 30
$CheckBoxColumn1.ReadOnly = $false

$DataGrid1 = New-Object System.Windows.Forms.DataGridView
$DataGrid1.Dock = "Fill"
$DataGrid1.BorderStyle = 'FixedSingle'
$DataGrid1.AlternatingRowsDefaultCellStyle.BackColor = 'LightGray'
$DataGrid1.AllowUserToAddRows = $false
$DataGrid1.RowHeadersVisible = $false
$DataGrid1.BackgroundColor = "White"
$DataGrid1.Columns.Add($CheckBoxColumn1) | Out-Null
$DataGrid1.ColumnCount = 3
$DataGrid1.Columns[1].name = 'col1'
$DataGrid1.Columns[2].name = 'col2'
$DataGrid1.Rows.add($false,'one','two')
$DataGrid1.Rows.add($false,'three','four')

##Add checkbox to header row column 0

$form.Controls.Add($DataGrid1)
$form.ShowDialog()




Aucun commentaire:

Enregistrer un commentaire