Grid: keep focus when refresh(?)

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 4 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
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Grid: keep focus when refresh(?)

Post by stevens »

Then it selects the first row as well as the other row.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid: keep focus when refresh(?)

Post by jvierra »

I really have no idea what you are doing. Just deselect all rows and set the row you want to be selected.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Grid: keep focus when refresh(?)

Post by stevens »

Never mind, it doesn't work at all anymore now.
After I did a simple change from yes to no, then again to yes, selection doesn't work. I give up.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid: keep focus when refresh(?)

Post by jvierra »

You can't use yes/no for Booleans. You must use the special variables $true and $false. Aby text will always evaluate to true even if it spelled "false" and PS doesn't recognize YES/NO or Ok or any other English terms.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Grid: keep focus when refresh(?)

Post by jvierra »

I had a few minutes today so I cobbled together a simple example of how this works so you can see if it matches what you are doing. Your actual code would have made this much easier.

The method used has variations depending on how your form's behavior is set.
Attachments
Test-DGVRowSelect.psf
(16.03 KiB) Downloaded 98 times
MiaMiller
Posts: 1
Last visit: Sun Mar 21, 2021 11:38 pm

Re: Grid: keep focus when refresh(?)

Post by MiaMiller »

In order to keep the focus on the line, I advise you to read the information on solving this problem in this foru . There are many helpful hints there.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Grid: keep focus when refresh(?)

Post by stevens »

jvierra wrote: Fri Oct 30, 2020 8:35 pm I had a few minutes today so I cobbled together a simple example of how this works so you can see if it matches what you are doing. Your actual code would have made this much easier.

The method used has variations depending on how your form's behavior is set.
Thanks! You didn't ask for the code btw.
Your example selects a cell, I would need to select a full row.

This is the code:

In Action "SelectionChanged" on DataGridview
$Global:LastSelectedRowDataGridView01 = $datagridview01.SelectedRows[0].Index

On Load of DatagridView01
$DataGridView01.[$LastSelectedRowDataGridView01].Selected = $true
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Grid: keep focus when refresh(?)

Post by stevens »

Ok, I see what is happening.
The selected index row is ok, but when refresh happens selectionchanged is also triggered and the value of selected index is 0 again :-(
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Grid: keep focus when refresh(?)

Post by stevens »

Ok, fixed it. Thanks for your help!
This topic is 3 years and 4 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