Datagrid item selection + "loading" while executing

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 7 years and 1 week 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
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Datagrid item selection + "loading" while executing

Post by stevens »

Product, version and build: PowerShell Studio 2017 v5.4.134
32 or 64 bit version of product: 64
Operating system: W2K12R2
32 or 64 bit OS: 64
PowerShell Version: 5.0.10586.117

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Hi,

I created a small example to show what I would like to achieve: a form which shows the result of an computer search in a gridview. When you select an item in the gridview, it will show below what you selected. Then while the search is running, I'd like to show "loading".

So my 2 questions:

1.Item selection works, but when you click several times on the result (richtextbox "you selected ..."), f.e. computer01, then computer03, then computerx then ... it stops working, then when you click further it works again.
Might be related to the fact I'm using $global:computername for it? Well, since this example is just a small extract of my full script and I used $computername everywhere, I'd like to keep the $global if possible. Then also the $global:computername gives me bigger flexibility and it makes the script more clear too.

2.Found spotlight on progressbar but don't know howto implement that for this particular search (https://www.sapien.com/blog/2011/07/14/ ... r-control/)
It would also be nice if my form wouldn't freeze, but then I'd need to use jobs, right? So,I'll start with "loading" first then ...
Update: found the $progressbaroverlay1.visible = $false and $progressbaroverlay1.visible = $true
options which are good enough for me for now.
Howver, the style "marquee" of the overlay doesn't move, just shows 1 green block. Would be nice if it would move so user knows it is doing something.


Please advise.
J
Attachments
TEST-DatagridViewResults.psf
Example2
(32.95 KiB) Downloaded 144 times
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Datagrid item selection + "loading" while executing

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
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: Datagrid item selection + "loading" while executing

Post by jvierra »

A progress bar will not move if the form is frozen.

Read the articles on" Creating responsive forms" again.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datagrid item selection + "loading" while executing

Post by jvierra »

Looking at you form tells me you must use the JobTracker custom control set. It will keep the form live during the search.

https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Datagrid item selection + "loading" while executing

Post by stevens »

Thanks. Any idea about the gridselection?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datagrid item selection + "loading" while executing

Post by jvierra »

Play around with this and look at how I created those behaviors. It might help you to better understand how forms are designed to work.

Because you are swallowing the enter key you will be forced to live with the "bong" every time it is pressed.
Attachments
AATEST-DatagridViewResults.psf
(29.34 KiB) Downloaded 144 times
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Datagrid item selection + "loading" while executing

Post by stevens »

Thanks!
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Datagrid item selection + "loading" while executing

Post by stevens »

Got somewhere but not sure howto add/format the code for the job

$items = Get-ADComputer -Filter { name -like 'mycomputer' } | select name, DNSHostName
$datagridview1.DataSource = ConvertTo-DataTable -InputObject $items

Could you advise?
Attachments
TEST-DatagridViewResults-2.psf
Sample
(51.42 KiB) Downloaded 136 times
User avatar
AdamUK
Posts: 31
Last visit: Fri Jun 22, 2018 2:29 am

Re: Datagrid item selection + "loading" while executing

Post by AdamUK »

Hi, I like to use datagridviews with things I do and loading bars etc. I'm no pro at designing powershell forms yet, but I believe your problem is not passing the data as an arguement. It seems like you have removed the -ArgumentList parameter
$buttonStartJob.Enabled = $false

#Create a New Job using the Job Tracker
Add-JobTracker -Name "JobName" `

So you could insert this just before the -Name parameter or if you load a default grid form you will see this at the bottom. Im at work right now so I cannot test this but my guess is you need to get the output of "$items = Get-ADComputer -Filter { name -like 'mycomputer' } | select name, DNSHostName" and get this in a variable or txt file then pass this in the -ArgumentList then in the bit of code
Param ($Argument1) #Pass any arguments using the ArgumentList parameter
Put your param in there. Hope this makes enough sense, this is how I get the data in all my datagridviews and it works. Not sure if this is the best method, but it does work. If you need more help maybe I can post an example tonight when I am at home and not work. :D
User avatar
AdamUK
Posts: 31
Last visit: Fri Jun 22, 2018 2:29 am

Re: Datagrid item selection + "loading" while executing

Post by AdamUK »

I do not know if this works, but this is the approach I mean...still at work btw so hence just trying to push you in the right direction....
  1. $buttonStartJob_Click = {
  2.    
  3.     $buttonStartJob.Enabled = $false
  4.     $items = Get-ADComputer -Filter { name -like 'mycomputer' } | Select-Object name, DNSHostName
  5.     #Create a New Job using the Job Tracker
  6.     Add-JobTracker -ArgumentList $items -Name "JobName" `
  7.                    -JobScript {
  8.         #--------------------------------------------------
  9.         #TODO: Set a script block
  10.         #Important: Do not access form controls from this script block.
  11.        
  12.         Param ($computers) #Pass any arguments using the ArgumentList parameter
  13.        
  14.        
  15.         Update-DataGridView -DataGridView $datagridview1 -Item $computers
This topic is 7 years and 1 week 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