Product, version and build: Powershell Studio 2022
Operating system: Windows 10
PowerShell version(s): 5+
I have a database that is structured something like...
Name,custID,Cover,overview,glossary
bank1,102,1,0,1
bank2,103,0,1,1
etc
I'd like to populate a datagridview with checkboxes that is populated from the above database. The checkboxes would be checked if the value of the row =1 and unchecked if = 0....is there a way to accomplish this?
Populate datagridview with checkboxes from SQL database
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- supportMIB
- Posts: 62
- Last visit: Thu Feb 29, 2024 11:17 am
Re: Populate datagridview with checkboxes from SQL database
[Topic moved by moderator to PowerShell GUIs forum]
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Populate datagridview with checkboxes from SQL database
You have to set the Checkbox properties to use the data values as checked or unchecked. Edit the column cell properties and set the required values.
- supportMIB
- Posts: 62
- Last visit: Thu Feb 29, 2024 11:17 am
Re: Populate datagridview with checkboxes from SQL database
I guess I'm still a little unsure how to import the SQL table to the datagridview when the columns are predetermined, can you provide a small example how I would do that if I manually set up the columns for the datagridview?
I'm using the below code to create a datatable that i'm using to populate the grid...if i prebuild the columns how can i use a datatable to populate those columns?
Here's an example of what i'm trying to do
I'm using the below code to create a datatable that i'm using to populate the grid...if i prebuild the columns how can i use a datatable to populate those columns?
Code: Select all
function Get-DatabaseTable
{
[OutputType([System.Data.DataTable])]
Param ()
#Load the database assembly
Add-Type -AssemblyName 'System.Data'
#Database Query
$QueryString = 'select * from NAME'
$connection_string = "Server = 10.x.x.x; Database = Table; Integrated Security = True; MultipleActiveResultSets=true;"
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connection_string
$connection.Open()
$command = New-Object System.Data.SqlClient.SqlCommand
$command.Connection = $connection
$Command.CommandText = $querystring
$adapter = New-Object System.Data.SqlClient.SqlDataAdapter ($command)
$dataset = New-Object System.Data.DataSet
[void]$adapter.Fill($dataset)
#Return the Dataset
return @( ,$dataset.Tables[0])
$table = Get-DatabaseTable
$datagridview1.DataSource = $table
Update-DataGridView -DataGridView $datagridview2 -Item $table
}