Page 2 of 2

Re: Grid: keep focus when refresh(?)

Posted: Fri Oct 30, 2020 3:04 am
by stevens
Then it selects the first row as well as the other row.

Re: Grid: keep focus when refresh(?)

Posted: Fri Oct 30, 2020 3:59 am
by jvierra
I really have no idea what you are doing. Just deselect all rows and set the row you want to be selected.

Re: Grid: keep focus when refresh(?)

Posted: Fri Oct 30, 2020 4:03 am
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.

Re: Grid: keep focus when refresh(?)

Posted: Fri Oct 30, 2020 4:06 am
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.

Re: Grid: keep focus when refresh(?)

Posted: Fri Oct 30, 2020 8:35 pm
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.

Re: Grid: keep focus when refresh(?)

Posted: Wed Nov 04, 2020 1:24 am
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.

Re: Grid: keep focus when refresh(?)

Posted: Tue Nov 17, 2020 6:07 am
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

Re: Grid: keep focus when refresh(?)

Posted: Tue Nov 17, 2020 6:13 am
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 :-(

Re: Grid: keep focus when refresh(?)

Posted: Fri Nov 20, 2020 6:16 am
by stevens
Ok, fixed it. Thanks for your help!