Hi,
I have a gridview which I do a refresh when certain action happens in the gridview.
Now when the refresh happens all items are reloaded and the focus goes to the first row.
Is there a way to keep the focus on the row which was selected before the refresh/reload of the grid?
J
Grid: keep focus when refresh(?)
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.
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.
Re: Grid: keep focus when refresh(?)
Ok, thanks. And how do I do that?
I can select an item in gridview, but never selected a row, then how to go to that row when refresh happens?
I can select an item in gridview, but never selected a row, then how to go to that row when refresh happens?
Re: Grid: keep focus when refresh(?)
Something like this?
In action selectionchanged
$Global:LastSelectedRowDataGridView = $dataGridView.SelectedRows[0].Index
Then in refresh
$datagridview.SelectedRows = $LastSelectedRowDataGridView
In action selectionchanged
$Global:LastSelectedRowDataGridView = $dataGridView.SelectedRows[0].Index
Then in refresh
$datagridview.SelectedRows = $LastSelectedRowDataGridView
Re: Grid: keep focus when refresh(?)
Note: tried solution above but did not work.
It says error "'SelectedRows' is a ReadOnly property..Exception.Message a"
It says error "'SelectedRows' is a ReadOnly property..Exception.Message a"
Re: Grid: keep focus when refresh(?)
Thanks, that works!
But now the grid has the first row AND the selected item. Is there a property I can deselect so it doesn't select first row in grid too?
Note: when I select another item in the grid, then select first row, after refresh it doesn't select first row but the other row in the grid which is confusing for GUI user.
But now the grid has the first row AND the selected item. Is there a property I can deselect so it doesn't select first row in grid too?
Note: when I select another item in the grid, then select first row, after refresh it doesn't select first row but the other row in the grid which is confusing for GUI user.
Last edited by stevens on Fri Oct 30, 2020 2:19 am, edited 1 time in total.
Re: Grid: keep focus when refresh(?)
Thanks, that works but then no item is selected in the gridview.