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.
This topic is 2 years and 3 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
User avatar
brianclark
Posts: 23
Last visit: Wed Feb 22, 2023 5:19 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: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 2 years and 3 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