Hi,
I am new to forms, While developing code in powershell studio I am facing some issues.
script is, multiform project, so when clicked on add servers in one form will open a 2nd form and in the textbox when I add servers and click ok, the form should close and bind this data to a datagridview in the first form as new lines for separate servers.
I am able to open a new form, but not able to bind the data to the datagrideview
can someone please help?
Datagrid binding
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.
Re: Datagrid binding
Hi - welcome to forms. Unfortunately there is not enough information to tell us what it is that you are having an issue with.
I recommend starting by reading through some of the articles in the "Information Center" section of this site. You will find many discussions that will help you to understand Forms and how to use them in PowerShell.
https://info.sapien.com/index.php/guis
The following article will explain how to pass and return values between forms:
https://info.sapien.com/index.php/guis/ ... sing-forms
The article says that form names start with "Call-". That has been changed to "Show-"
I recommend starting by reading through some of the articles in the "Information Center" section of this site. You will find many discussions that will help you to understand Forms and how to use them in PowerShell.
https://info.sapien.com/index.php/guis
The following article will explain how to pass and return values between forms:
https://info.sapien.com/index.php/guis/ ... sing-forms
The article says that form names start with "Call-". That has been changed to "Show-"
-
- Posts: 4
- Last visit: Sun Oct 20, 2019 11:10 pm
Re: Datagrid binding
I am able to copy the data to the Grid. But the data which is entered in Textbox1, is not copied to grid as rows.
instead it is copying in single cell.
attached the forms. Main form and add serves form.
Can someone please help?
instead it is copying in single cell.
attached the forms. Main form and add serves form.
Can someone please help?
- Attachments
-
- MainForm.psf
- (29.44 KiB) Downloaded 88 times
-
- AddServer.psf
- (18.03 KiB) Downloaded 77 times
Re: Datagrid binding
You cannot at plain text to a grid. You must add rows and satisfy all columns for each row.
See: https://docs.microsoft.com/en-us/dotnet ... tem_Object___
$row = @('col1','col2',col3', …)
$datagridview1.Rows.Add($row)
See: https://docs.microsoft.com/en-us/dotnet ... tem_Object___
$row = @('col1','col2',col3', …)
$datagridview1.Rows.Add($row)
-
- Posts: 4
- Last visit: Sun Oct 20, 2019 11:10 pm
Re: Datagrid binding
Thanks for the reply, still didnt get as I am new to coding.
Can you please help me how to add the text from textbox1 to Grid as rows?
can you share the snippet in the code?
Can you please help me how to add the text from textbox1 to Grid as rows?
can you share the snippet in the code?
Re: Datagrid binding
I posted the answer in my previous post. You must add the textbox as a column in an array of column text values. Try the code example I posted after reading the link I posted.
-
- Posts: 4
- Last visit: Sun Oct 20, 2019 11:10 pm
Re: Datagrid binding
I removed all columns except ServerName, still the data comes to only one column cell
- function Add-Servers
- {
- if ((Show-AddServer_psf) -eq 'OK')
- {
- #When you call a form, you get return value variables:
- $Servers = @($AddServer_addservers_textbox1)
- foreach ($server in $Servers)
- {
- $datagridview1.Rows.Add($server)
- }
- }
- }