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

Re: Datagrid item selection + "loading" while executing

Post by stevens »

I uploaded an example here, hope that makes it more clear what is happening = form in which software installed is loaded. The richtextbox shows which item you selected, I would like to add manipulations on those selections later.
Selection (clicking on an item in the gridview) works well sometimes but then some clicks (selections) nothing happens, then it selects again correctly.
Attachments
ExampleSelectionNOTok.psf
(320.57 KiB) Downloaded 138 times
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 »

Your example runs with many errors. It is stopping functioning because of some code that is being executed. I don't think anyone is going to want to debug 1000 lines of your code for you.

I can see no reason for so many lines to just click a row. Try starting a new PSF and just add the minimum code required to test the grid. After you get the minimal amount working then add the other pieces a little at a time util you find where the code is damaged.

All programmers have to learn how to debug code. It can be very challenging if you have a limited understanding of the technology that you are trying to debug wit but it is how we all learn. There are many blogs, books and magazines that dedicate time to issues of debugging difficult programs.

You will also find it easier to use SelectionChanged and full row select. This will be easier to manage and is also closer to how we manage a grid result. Consider that the grid is "global" and its values are accessible when you wan to use them. There is no need to capture them in set of global variables.

TO design manageable software it is necessary to have a clear statement of what you are expecting in terms of inputs, outputs and behaviors. I can see you are loading a grid and selecting something. It appears that you are trying to force the script to use a progress bar but it is not clear why you need one. Loading those registry keys takes only a second.
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 »

Reduced the code to few hundred lines & the job. Most of the lines are there for the form/datagrid.
Please have a second look.
Attachments
ExampleSelectionNOTok2.psf
(312.54 KiB) Downloaded 124 times
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 »

Your example still throw dozens of errors when it starts and leaves me with a blank screen.

As I noted - do not use invoke to the local system. It will give issues as I am seeing.
  1. >> Building (ExampleSelectionNOTok2.psf) ...
  2. >> Platform: V5 64Bit (STA) (Forced)
  3. ERROR: [ALPHA] Connecting to remote server ALPHA failed with the following error message : WinRM cannot process the request. The following error with errorcode
  4. ERROR: 0x8009030e occurred while using Negotiate authentication: A specified logon session does not exist. It may already have been terminated.
  5. ERROR:  Possible causes are:
  6. ERROR:   -The user name or password specified are invalid.
  7. ERROR:   -Kerberos is used when no authentication method and no user name are specified.
  8. ERROR:   -Kerberos accepts domain user names, but not local user names.
  9. ERROR:   -The Service Principal Name (SPN) for the remote computer name and port does not exist.
  10. ERROR:   -The client and remote computers are in different domains and there is no trust between the two domains.
  11. ERROR:  After checking for the above issues, try the following:
  12. ERROR:   -Check the Event Viewer for events related to authentication.
  13. ERROR:   -Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
  14. ERROR:  Note that computers in the TrustedHosts list might not be authenticated.
  15. ERROR:    -For more information about WinRM configuration, run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting
  16. ERROR: Help topic.
  17. ERROR:     + CategoryInfo          : OpenError: (ALPHA:String) [], PSRemotingTransportException
  18. ERROR:     + FullyQualifiedErrorId : 1312,PSSessionStateBroken
  19. ERROR: ConvertTo-DataTable : Cannot validate argument on parameter 'InputObject'. The argument is null. Provide a valid value for the argument, and then try running
  20. E
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 »

I just did what I asked you to do. I set full row select, removed cell click and added this event:
  1. $datagridviewResults_SelectionChanged={
  2.     if($datagridviewResults.SelectedRows){
  3.         $software = $datagridviewResults.SelectedRows[0].Cells['DisplayName'].Value
  4.         $SoftwareVersion = $datagridviewResults.SelectedRows[0].Cells['DisplayVersion'].Value
  5.         Add-Logs -text "Your selection: Software $software name Version $SoftwareVersion SoftwareType $SoftwareVersion"
  6.     }
  7. }
It now works without losing selections.
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 »

This is how to easily do a sortable datetime.
  1. function Add-Logs{
  2.     [CmdletBinding()]
  3.     param ($text)
  4.     $date = get-date -Format s
  5.     $richtextboxExternalFormSoftwareLogging.Text += "[$date] - $text`r"
  6. }
Your method does not produce a sortable pattern.
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 »

Replacing selection by your code? Thanks but for me it doesn't work.
Attachments
ExampleSelectionNOTok2.psf
(312.5 KiB) Downloaded 128 times
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 »

It works on the sample you posted just fine.
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 »

Remember - I posted that you have to set "FullRowSelect". This is how to get the row into the selected state on a single click.
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 »

Ok, got it working, thanks!
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