datagridview event firing

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 3 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: datagridview event firing

Post by jvierra »

Sorry but your code makes no sense. You cannot name a column as a Boolean. A column must have a name and a value.

Code: Select all

$users = Get-AdUser -Filter { Surname -like $searchString } -SearchBase "OU=xxx,DC=xxx,DC=xxx,DC=xxx,DC=xxx" | 
    Select-Object @{n='Check';e={$false}},GivenName, Surname
$datagridview1.DataSource = [System.Collections.ArrayList]$users
User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Re: datagridview event firing

Post by IanUoY »

The $false was my way of not applying anything to that column and setting it to unchecked as it is a checkbox.

I'll check your code.

(Incidentally, if I did use buttons, is they a way of setting the text of the an individual button in the grid?)
User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Re: datagridview event firing

Post by IanUoY »

Ok, your code I get now.
However, it appends columns to my existing datagridview. How to I place selected rows into the existing design. Also, can I add GivenName and Surname to create one column via the select method?
Do you have any videos, etc with regard to the datagridview and how to best use?
Thanks
Ian
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: datagridview event firing

Post by jvierra »

Don't define any columns. The grid will auto-create the columns correctly.
User avatar
IanUoY
Posts: 91
Last visit: Wed Sep 20, 2023 2:44 am

Re: datagridview event firing

Post by IanUoY »

ok thanks but how do I add two selected columns together?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: datagridview event firing

Post by jvierra »

What does that mean? Columns are not added together.

Are you trying to concatenate two properties into one column?

Code: Select all

$users = Get-AdUser -Properties GivenName,SurName -Filter { Surname -like $searchString } -SearchBase "OU=xxx,DC=xxx,DC=xxx,DC=xxx,DC=xxx" | 
    Select-Object @{n='Check';e={$false}},@{n='Name';e={$_.GivenName+' '+$_.Surname}},SamAccountName
$datagridview1.DataSource = [System.Collections.ArrayList]$users
Before trying to work with something as complex as Forms you should take the time to learn PowerShell. It will save you a lot of time and frustration.

Windows PowerShell™ 4: TFM
This topic is 3 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked