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.
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
Shrek1515
Posts: 10
Last visit: Sat Oct 24, 2020 12:32 pm

datagridview not populating

Post by Shrek1515 »

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

Thanks
Attachments
PS.txt
(915 Bytes) Downloaded 88 times
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Sat Oct 24, 2020 12:32 pm

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
Last visit: Sat Oct 24, 2020 12:32 pm

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 86 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Sat Oct 24, 2020 12:32 pm

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
Last visit: Sat Oct 24, 2020 12:32 pm

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 2333 times
Code.JPG
Code.JPG (169.62 KiB) Viewed 2333 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: datagridview not populating

Post by jvierra »

And where is it hanging? It can only be hanging on the Get-AzVM.
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