Programatically add a new row to a databound datagridview.

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.
Locked
User avatar
brianclark
Posts: 13
Last visit: Thu Jan 20, 2022 2:18 pm

Programatically add a new row to a databound datagridview.

Post by brianclark »

Product, version and build: Sapien Powershell Studio 2021, 5.8.194
Operating system: Windows Server 2019 Data Center
PowerShell version(s): 5.1

I feel like this should be easier than I am making it on myself.
I have a 4 column datagridview (firstName, lastName, eMail, samAccountName), which is built bound to a datasource. I have two methods of entry into this datagridview;
1. Load a CSV
2 Manual entry via a secondary form which is called by a button click.
I would like to be able to, using the secondary form, add a new row of data (or multiple) to the current datagridview. For some reason, I am having a hard time wrapping my head around how to complete this. If someone could give me a little guidance, it would be much appreciated.

thanks,
Brian
User avatar
Alexander Riedel
Posts: 7873
Last visit: Fri Jan 28, 2022 8:52 am
Answers: 11
Been upvoted: 17 times

Re: Programatically add a new row to a databound datagridview.

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15052
Last visit: Wed Jan 26, 2022 2:55 pm
Answers: 17
Has voted: 3 times
Been upvoted: 13 times

Re: Programatically add a new row to a databound datagridview.

Post by jvierra »

Just add a new row to the DataTable object. See docs for DataTable and examples of how to add a row.
Locked