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.
User avatar
stevens
Posts: 434
Joined: Wed Jun 15, 2016 2:26 am

Re: Grid: keep focus when refresh(?)

Post by stevens »

Then it selects the first row as well as the other row.

jvierra
Posts: 14615
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 434
Joined: Wed Jun 15, 2016 2:26 am

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: 14615
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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: 14615
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

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 8 times

MiaMiller
Posts: 1
Joined: Wed Nov 04, 2020 1:18 am
Contact:

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: 434
Joined: Wed Jun 15, 2016 2:26 am

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: 434
Joined: Wed Jun 15, 2016 2:26 am

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: 434
Joined: Wed Jun 15, 2016 2:26 am

Re: Grid: keep focus when refresh(?)

Post by stevens »

Ok, fixed it. Thanks for your help!

Post Reply