@atm87

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

Есть запрос:
$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
  • Вопрос задан
  • 107 просмотров
Пригласить эксперта
Ответы на вопрос 1
@NortheR73
системный инженер
на 100% истину претендовать не буду...
DataGridView Control (Windows Forms)
DataGridView Control Overview (Windows Forms)
Column Types in the Windows Forms DataGridView Control
1. Это Windows Forms...Многие вещи там приколочены гвоздями, и их не поменять
2. То, что вы хотите поменять на CheckBox - это Row Header, и его можно скрыть/показать, поменять на что-то другое нельзя (могу ошибаться - более сведущие коллеги поправят ответами/комментариями)
3. у DataGridView есть тип столбца DataGridViewCheckBoxColumn
4. Мое видение решения: добавить в DataGridView первый столбец с типом DataGridViewCheckBoxColumn, остальные столбцы - как есть, далее скрыть Row Header

Как вариант - использовать WPF вместо WinForms
еще ссылки:
https://adamtheautomator.com/powershell-gui
https://www.foxdeploy.com/blog/part-i-creating-pow...
https://techgenix.com/building-powershell-gui-part1/
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы