datagridview not populating

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.
Shrek1515
Posts: 10
Joined: Tue Jul 28, 2020 8:37 am

datagridview not populating

Post by Shrek1515 »

Unable to copy code here, so please see attached file.

Thanks
Attachments
PS.txt
(915 Bytes) Downloaded 40 times

User avatar
Alexander Riedel
Posts: 7556
Joined: Tue May 29, 2007 4:43 pm
Answers: 1
Been upvoted: 4 times

Re: datagridview not populating

Post by Alexander Riedel »

[Topic moved by moderator]
Please do not put your entire post in a file. A short code sequence can be posted as text in this forum.
Longer code is preferably attached as a file, but still, the explanation of a problem or the question itself should be added to the post's text.
Thanks you for understanding.
Alexander Riedel
SAPIEN Technologies, Inc.

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: datagridview not populating

Post by jvierra »

Code: Select all

$button1_Click={
	#TODO: Place custom script here$
	$s = Get-Service
	$t = ConvertTo-DataTable -InputObject $s
	$datagridview1.DataSource = $t
}

Shrek1515
Posts: 10
Joined: Tue Jul 28, 2020 8:37 am

Re: datagridview not populating

Post by Shrek1515 »

Alexander Riedel wrote:
Wed Aug 05, 2020 8:52 am
[Topic moved by moderator]
Please do not put your entire post in a file. A short code sequence can be posted as text in this forum.
Longer code is preferably attached as a file, but still, the explanation of a problem or the question itself should be added to the post's text.
Thanks you for understanding.
Thank you Alexander.

Shrek1515
Posts: 10
Joined: Tue Jul 28, 2020 8:37 am

Re: datagridview not populating

Post by Shrek1515 »

jvierra wrote:
Wed Aug 05, 2020 12:38 pm

Code: Select all

$button1_Click={
	#TODO: Place custom script here$
	$s = Get-Service
	$t = ConvertTo-DataTable -InputObject $s
	$datagridview1.DataSource = $t
}
Unfortunately, it still did not work after changing the code as described. Button2 behaviour remains the same, form freezes. Get-AZVM command runs fine when selected and run by right-clicking. Code attached here.

Thanks
Attachments
Code2.txt
(358 Bytes) Downloaded 36 times

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: datagridview not populating

Post by jvierra »

No idea what you mean by right-clicking. A button takes a single click.

The Get-AzVM command can hang which has little to do with how to load the grid. Without more accurate information there is no way to advise you.

Shrek1515
Posts: 10
Joined: Tue Jul 28, 2020 8:37 am

Re: datagridview not populating

Post by Shrek1515 »

Sorry, I meant right clicking in the script pane (not GUI) to test the command actually works on its own or not. Get-AZVM command works like get-process or get-service, and gives a list of VMs in tabular format.

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: datagridview not populating

Post by jvierra »

What script pane? Right click opens a context menu. You have to be clear and provide complete information. Create a simple form with a button and a grid and lace my code in the button to see how it works.

Shrek1515
Posts: 10
Joined: Tue Jul 28, 2020 8:37 am

Re: datagridview not populating

Post by Shrek1515 »

My form is simple, just 2 buttons and a datagridview. Attached screenshots, hope this helps.

Thanks.
Form.JPG
Form.JPG (31.83 KiB) Viewed 941 times
Code.JPG
Code.JPG (169.62 KiB) Viewed 941 times

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: datagridview not populating

Post by jvierra »

And where is it hanging? It can only be hanging on the Get-AzVM.

Locked